コード例 #1
0
ファイル: AddColumn.cs プロジェクト: dcga/HybridDb
        public AddColumn(string tablename, Column column)
        {
            RequiresReprojectionOf = tablename;

            Tablename = tablename;
            Column = column;
        }
コード例 #2
0
ファイル: DocumentTable.cs プロジェクト: asgerhallas/HybridDb
        public DocumentTable(string name)
            : base(name)
        {
            IdColumn = new SystemColumn("Id", typeof(string), length: 1024, isPrimaryKey: true);
            Register(IdColumn);

            EtagColumn = new SystemColumn("Etag", typeof(Guid));
            Register(EtagColumn);

            CreatedAtColumn = new SystemColumn("CreatedAt", typeof(DateTimeOffset));
            Register(CreatedAtColumn);

            ModifiedAtColumn = new SystemColumn("ModifiedAt", typeof(DateTimeOffset));
            Register(ModifiedAtColumn);

            DocumentColumn = new Column("Document", typeof(byte[]));
            Register(DocumentColumn);

            MetadataColumn = new Column("Metadata", typeof(byte[]));
            Register(MetadataColumn);

            DiscriminatorColumn = new Column("Discriminator", typeof(string), length: 1024);
            Register(DiscriminatorColumn);

            AwaitsReprojectionColumn = new Column("AwaitsReprojection", typeof(bool));
            Register(AwaitsReprojectionColumn);

            VersionColumn = new Column("Version", typeof(int));
            Register(VersionColumn);
        }
コード例 #3
0
ファイル: SqlTypeMap.cs プロジェクト: dcga/HybridDb
 public static SqlColumn Convert(Column column)
 {
     if (!ForNetType(column.Type).Any())
         throw new ArgumentException("Can only project .NET simple types, Guid, DateTime, DateTimeOffset, TimeSpan and byte[].");
     
     return new SqlColumn(ForNetType(column.Type).First().DbType, GetLength(column));
 }
コード例 #4
0
ファイル: Column.cs プロジェクト: dcga/HybridDb
 protected bool Equals(Column other)
 {
     return Name == other.Name &&
            Type == other.Type &&
            Length == other.Length &&
            Nullable == other.Nullable &&
            IsPrimaryKey == other.IsPrimaryKey &&
            Equals(DefaultValue, other.DefaultValue);
 }
コード例 #5
0
        protected SqlBuilder GetColumnSqlType(Column column, string defaultValuePostfix = "")
        {
            if (column.Type == null)
                throw new ArgumentException($"Column {column.Name} must have a type");

            var sql = new SqlBuilder();

            var sqlColumn = SqlTypeMap.Convert(column);
            sql.Append(new SqlParameter { DbType = sqlColumn.DbType }.SqlDbType.ToString());
            sql.Append(sqlColumn.Length != null, "(" + sqlColumn.Length + ")");
            sql.Append(column.Nullable, "NULL").Or("NOT NULL");
            sql.Append(column.DefaultValue != null, "DEFAULT '{0}'", column.DefaultValue);
            sql.Append(column.IsPrimaryKey, " PRIMARY KEY");

            return sql;
        }
コード例 #6
0
ファイル: SqlTypeMap.cs プロジェクト: dcga/HybridDb
        static int? GetLength(Column column)
        {
            if (column.Length != null)
                return column.Length;

            if (column.Type == typeof (string))
                return Int32.MaxValue;
            
            if (column.Type == typeof(Enum))
                return 255;
            
            if (column.Type == typeof (byte[]))
                return Int32.MaxValue;

            return null;
        }
コード例 #7
0
ファイル: SqlTypeMap.cs プロジェクト: asgerhallas/HybridDb
        static string GetLength(Column column)
        {
            if (column.Length != null)
                return column.Length == -1 ? "MAX" : column.Length.ToString();

            if (column.Type == typeof (string))
                return "1024";

            if (column.Type == typeof(Enum))
                return "255";

            if (column.Type == typeof (byte[]))
                return "MAX";

            if (column.Type == typeof (decimal))
                return "28, 14";

            return null;
        }
コード例 #8
0
ファイル: ColumnTests.cs プロジェクト: dcga/HybridDb
 public void ColumnGetsNullabilityFromType(Type columnType, bool isNullable)
 {
     var column = new Column("SomeColumn", columnType);
     column.Nullable.ShouldBe(isNullable);
 }
コード例 #9
0
ファイル: ColumnTests.cs プロジェクト: dcga/HybridDb
 public void PrimaryKeyColumnCanNotBeNullable(Type columnType)
 {
     var column = new Column("SomeColumn", columnType, isPrimaryKey: true);
     column.Nullable.ShouldBe(false);
 }
コード例 #10
0
 public ChangeColumnType(string tableName, Column column)
 {
     Unsafe = true;
     TableName = tableName;
     Column = column;
 }
コード例 #11
0
 public ColumnAlreadRegisteredException(Table table, Column column)
     : base(string.Format("The table {0} already has a column named {1} and is not of the same type.", table.Name, column.Name)) {}
コード例 #12
0
ファイル: Table.cs プロジェクト: dcga/HybridDb
 public void Register(Column column)
 {
     columns.Add(column.Name, column);
 }