Ejemplo n.º 1
0
        public static IEnumerable <string> AllColumnNames(ISqlTableMetadata tableMetadata)
        {
            var list = NonCustomColumnNames(tableMetadata).ToList();

            list.AddRange(tableMetadata.CustomColumnNames);
            return(list);
        }
Ejemplo n.º 2
0
        public static IEnumerable <string> ReadColumnNames(ISqlTableMetadata tableMetadata)
        {
            var list = new List <string> {
                "Id"
            };

            if (tableMetadata.EtagColumnName != null)
            {
                list.Add(tableMetadata.EtagColumnName);
            }
            if (tableMetadata.RowVersionColumnName != null)
            {
                list.Add(tableMetadata.RowVersionColumnName);
            }
            if (tableMetadata.CreatedAtColumnName != null)
            {
                list.Add(tableMetadata.CreatedAtColumnName);
            }
            if (tableMetadata.UpdatedAtColumnName != null)
            {
                list.Add(tableMetadata.UpdatedAtColumnName);
            }
            list.AddRange(tableMetadata.CustomColumnNames);
            return(list);
        }
Ejemplo n.º 3
0
        public static string UpdateList(ISqlTableMetadata tableMetadata)
        {
            var allUpdates = new List <string>();

            allUpdates.AddRange(UpdatesForStandardColumns(tableMetadata));
            allUpdates.AddRange(tableMetadata.CustomColumnNames.Select(name => $"[{name}]=@{name}"));
            return(string.Join(",", allUpdates));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="options">Options for this table</param>
 /// <param name="tableMetadata">The configuration for this table</param>
 /// <param name="parentColumnName">The name of the column that points out an id in the parent table.</param>
 /// <param name="parentTable">The parent table </param>
 public ManyToOneSql(IDatabaseOptions options, ISqlTableMetadata tableMetadata, string parentColumnName,
                     CrudSql <TOneModel> parentTable)
     : base(options, tableMetadata)
 {
     ParentColumnName = parentColumnName;
     ParentTable      = parentTable;
     _convenience     = new ManyToOneConvenience <TManyModel, TManyModel, Guid>(this);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="options"></param>
        /// <param name="tableMetadata"></param>
        protected TableBase(IDatabaseOptions options, ISqlTableMetadata tableMetadata)
        {
            InternalContract.RequireNotNull(options, nameof(options));
            InternalContract.RequireValidated(tableMetadata, nameof(tableMetadata));

            Database      = new Database(options);
            TableMetadata = tableMetadata;
        }
Ejemplo n.º 6
0
        private static IEnumerable <string> UpdatesForStandardColumns(ISqlTableMetadata tableMetadata)
        {
            var list = new List <string>();

            if (tableMetadata.EtagColumnName != null)
            {
                list.Add($"{tableMetadata.EtagColumnName}='{Guid.NewGuid()}'");
            }
            if (tableMetadata.UpdatedAtColumnName != null)
            {
                list.Add($"{tableMetadata.UpdatedAtColumnName}=sysutcdatetime()");
            }
            return(list);
        }
Ejemplo n.º 7
0
        public static IEnumerable <string> NonCustomColumnNames(ISqlTableMetadata tableMetadata)
        {
            var list = new List <string> {
                "Id"
            };

            if (tableMetadata.EtagColumnName != null)
            {
                list.Add(tableMetadata.EtagColumnName);
            }
            if (tableMetadata.CreatedAtColumnName != null)
            {
                list.Add(tableMetadata.CreatedAtColumnName);
            }
            if (tableMetadata.UpdatedAtColumnName != null)
            {
                list.Add(tableMetadata.UpdatedAtColumnName);
            }
            return(list);
        }
Ejemplo n.º 8
0
 public static string CreateArgumentList(ISqlTableMetadata tableMetadata) => string.Join(", ", CreateColumnNames(tableMetadata).Select(name => $"@{name}"));
Ejemplo n.º 9
0
 public static string Delete(ISqlTableMetadata tableMetadata, string where) => $"DELETE FROM [{tableMetadata.TableName}] WHERE {where}";
Ejemplo n.º 10
0
 public static string ReadColumnList(ISqlTableMetadata tableMetadata) => string.Join(", ", ReadColumnNames(tableMetadata).Select(name => $"[{name}]"));
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="connectionString"></param>
 /// <param name="tableMetadata"></param>
 /// <param name="groupColumnName"></param>
 /// <param name="foreignHandler"></param>
 public ForeignKeyTableHandler(string connectionString, ISqlTableMetadata tableMetadata, string groupColumnName, TableBase <TForeignItem> foreignHandler)
     : base(connectionString, tableMetadata)
 {
     GroupColumnName = groupColumnName;
     ForeignHandler  = foreignHandler;
 }
Ejemplo n.º 12
0
 public static string Update(ISqlTableMetadata tableMetadata) => $"UPDATE [{tableMetadata.TableName}] SET {UpdateList(tableMetadata)} WHERE Id = @Id";
Ejemplo n.º 13
0
 /// <summary>
 /// Constructor
 /// </summary>
 public CrudSql(IDatabaseOptions options, ISqlTableMetadata tableMetadata)
     : base(options, tableMetadata)
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="connectionString"></param>
 /// <param name="tableMetadata"></param>
 /// <param name="parentColumnName"></param>
 /// <param name="oneTableHandler"></param>
 public ManyToOneSql(string connectionString, ISqlTableMetadata tableMetadata, string parentColumnName,
                     CrudSql <TOneModel> oneTableHandler)
     : base(connectionString, tableMetadata, parentColumnName, oneTableHandler)
 {
 }
 public DependentToMasterSql(string connectionString, ISqlTableMetadata tableMetadata,
                             CrudSql <TDependentModel> dependentTableHandler, CrudSql <TMasterModel> masterTableHandler)
     : base(connectionString, tableMetadata, dependentTableHandler, masterTableHandler)
 {
 }
 public DependentToMasterSql(IDatabaseOptions options, ISqlTableMetadata tableMetadata,
                             CrudSql <TDependentModel> dependentTableHandler, CrudSql <TMasterModel> masterTableHandler)
     : base(options, tableMetadata, dependentTableHandler, masterTableHandler)
 {
 }
Ejemplo n.º 17
0
 public static string Read(ISqlTableMetadata tableMetadata, string where) => $"SELECT {ReadColumnList(tableMetadata)} FROM [{tableMetadata.TableName}] WHERE {where}";
Ejemplo n.º 18
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="connectionString"></param>
 /// <param name="tableMetadata"></param>
 /// <param name="parentColumnName"></param>
 /// <param name="masterTableHandler"></param>
 public SlaveToMasterSql(string connectionString, ISqlTableMetadata tableMetadata, string parentColumnName,
                         CrudSql <TSlaveModel> slaveTableHandler, CrudSql <TMasterModel> masterTableHandler)
     : base(connectionString, tableMetadata, parentColumnName, slaveTableHandler, masterTableHandler)
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="options"></param>
 /// <param name="tableMetadata"></param>
 /// <param name="groupColumnName1"></param>
 /// <param name="referenceHandler1"></param>
 /// <param name="groupColumnName2"></param>
 /// <param name="referenceHandler2"></param>
 public ManyToManySql(IDatabaseOptions options, ISqlTableMetadata tableMetadata, string groupColumnName1,
                      CrudSql <TReferenceModel1> referenceHandler1, string groupColumnName2,
                      CrudSql <TReferenceModel2> referenceHandler2)
     : base(options, tableMetadata, groupColumnName1, referenceHandler1, groupColumnName2, referenceHandler2)
 {
 }
Ejemplo n.º 20
0
 public static string Create(ISqlTableMetadata tableMetadata) => $"INSERT INTO dbo.[{tableMetadata.TableName}] ({CreateColumnList(tableMetadata)}) values ({CreateArgumentList(tableMetadata)})";
Ejemplo n.º 21
0
 protected TableBase(string connectionString, ISqlTableMetadata tableMetadata) : this(new DatabaseOptions() { ConnectionString = connectionString }, tableMetadata)
 {
 }
Ejemplo n.º 22
0
 public static string Read(ISqlTableMetadata tableMetadata, string where, string orderBy) => $"SELECT {ReadColumnList(tableMetadata)} FROM [{tableMetadata.TableName}] WHERE {where} ORDER BY {orderBy}";
Ejemplo n.º 23
0
 public static string Update(ISqlTableMetadata tableMetadata, string oldEtag) => $"UPDATE [{tableMetadata.TableName}] SET {UpdateList(tableMetadata)} WHERE Id = @Id AND Etag = '{oldEtag}'";
Ejemplo n.º 24
0
 public CrudSql(string connectionString, ISqlTableMetadata tableMetadata)
     : base(connectionString, tableMetadata)
 {
     InternalContract.RequireValidated(tableMetadata, nameof(tableMetadata));
 }
Ejemplo n.º 25
0
 public static string UpdateIfSameEtag(ISqlTableMetadata tableMetadata, string oldEtag) => $"UPDATE [{tableMetadata.TableName}] SET {UpdateList(tableMetadata)} WHERE Id = @Id AND {tableMetadata.EtagColumnName} = '{oldEtag}'";
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="connectionString"></param>
 /// <param name="tableMetadata"></param>
 /// <param name="groupColumnName1"></param>
 /// <param name="foreignHandler1"></param>
 /// <param name="groupColumnName2"></param>
 /// <param name="foreignHandler2"></param>
 public DoubleForeignTableHandler(string connectionString, ISqlTableMetadata tableMetadata, string groupColumnName1, TableBase <TForeignModel1> foreignHandler1, string groupColumnName2, TableBase <TForeignModel2> foreignHandler2)
     : base(connectionString, tableMetadata)
 {
     ForeignKeyTableHandler1 = new ForeignKeyTableHandler <TDatabaseItem, TForeignModel1>(connectionString, tableMetadata, groupColumnName1, foreignHandler1);
     ForeignKeyTableHandler2 = new ForeignKeyTableHandler <TDatabaseItem, TForeignModel2>(connectionString, tableMetadata, groupColumnName2, foreignHandler2);
 }
Ejemplo n.º 27
0
 public static string UpdateIfSameRowVersion(ISqlTableMetadata tableMetadata) => $"UPDATE [{tableMetadata.TableName}] SET {UpdateList(tableMetadata)} WHERE Id = @Id AND {tableMetadata.RowVersionColumnName} = @{tableMetadata.RowVersionColumnName}";
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="connectionString"></param>
 /// <param name="tableMetadata"></param>
 /// <param name="groupColumnName1"></param>
 /// <param name="referenceHandler1"></param>
 /// <param name="groupColumnName2"></param>
 /// <param name="referenceHandler2"></param>
 public ManyToManySql(string connectionString, ISqlTableMetadata tableMetadata, string groupColumnName1,
                      CrudSql <TReferenceModel1> referenceHandler1, string groupColumnName2,
                      CrudSql <TReferenceModel2> referenceHandler2)
     : base(connectionString, tableMetadata, groupColumnName1, referenceHandler1, groupColumnName2, referenceHandler2)
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="connectionString"></param>
 /// <param name="tableMetadata"></param>
 public TableBase(string connectionString, ISqlTableMetadata tableMetadata)
 {
     InternalContract.RequireValidated(tableMetadata, nameof(tableMetadata));
     Database      = new Database(connectionString);
     TableMetadata = tableMetadata;
 }