diff --git a/contracts/database/schema/blueprint.go b/contracts/database/schema/blueprint.go index 566e4135a..092ff3ee8 100644 --- a/contracts/database/schema/blueprint.go +++ b/contracts/database/schema/blueprint.go @@ -11,6 +11,8 @@ type Blueprint interface { BigInteger(column string) ColumnDefinition // Build Execute the blueprint to build / modify the table. Build(query orm.Query, grammar Grammar) error + // Char Create a new char column on the table. + Char(column string, length ...int) ColumnDefinition // Create Indicate that the table needs to be created. Create() // Decimal Create a new decimal column on the table. @@ -19,6 +21,8 @@ type Blueprint interface { Double(column string) ColumnDefinition // DropIfExists Indicate that the table should be dropped if it exists. DropIfExists() + // Enum Create a new enum column on the table. + Enum(column string, array []string) ColumnDefinition // Float Create a new float column on the table. Float(column string, precision ...int) ColumnDefinition // Foreign Specify a foreign key for the table. @@ -31,10 +35,6 @@ type Blueprint interface { GetTableName() string // HasCommand Determine if the blueprint has a specific command. HasCommand(command string) bool - // MediumIncrements Create a new auto-incrementing medium integer (3-byte) column on the table. - MediumIncrements(column string) ColumnDefinition - // MediumInteger Create a new medium integer (3-byte) column on the table. - MediumInteger(column string) ColumnDefinition // ID Create a new auto-incrementing big integer (8-byte) column on the table. ID(column ...string) ColumnDefinition // Increments Create a new auto-incrementing integer (4-byte) column on the table. @@ -45,6 +45,18 @@ type Blueprint interface { Integer(column string) ColumnDefinition // IntegerIncrements Create a new auto-incrementing integer (4-byte) column on the table. IntegerIncrements(column string) ColumnDefinition + // Json Create a new json column on the table. + Json(column string) ColumnDefinition + // Jsonb Create a new jsonb column on the table. + Jsonb(column string) ColumnDefinition + // LongText Create a new long text column on the table. + LongText(column string) ColumnDefinition + // MediumIncrements Create a new auto-incrementing medium integer (3-byte) column on the table. + MediumIncrements(column string) ColumnDefinition + // MediumInteger Create a new medium integer (3-byte) column on the table. + MediumInteger(column string) ColumnDefinition + // MediumText Create a new medium text column on the table. + MediumText(column string) ColumnDefinition // Primary Specify the primary key(s) for the table. Primary(column ...string) // SetTable Set the table that the blueprint operates on. @@ -55,10 +67,14 @@ type Blueprint interface { SmallInteger(column string) ColumnDefinition // String Create a new string column on the table. String(column string, length ...int) ColumnDefinition + // Text Create a new text column on the table. + Text(column string) ColumnDefinition // TinyIncrements Create a new auto-incrementing tiny integer (1-byte) column on the table. TinyIncrements(column string) ColumnDefinition // TinyInteger Create a new tiny integer (1-byte) column on the table. TinyInteger(column string) ColumnDefinition + // TinyText Create a new tiny text column on the table. + TinyText(column string) ColumnDefinition // ToSql Get the raw SQL statements for the blueprint. ToSql(grammar Grammar) []string // UnsignedBigInteger Create a new unsigned big integer (8-byte) column on the table. diff --git a/contracts/database/schema/column.go b/contracts/database/schema/column.go index d7c23de65..ebcd25b01 100644 --- a/contracts/database/schema/column.go +++ b/contracts/database/schema/column.go @@ -5,6 +5,8 @@ type ColumnDefinition interface { AutoIncrement() ColumnDefinition // Comment sets the comment value Comment(comment string) ColumnDefinition + // GetAllowed returns the allowed value + GetAllowed() []string // GetAutoIncrement returns the autoIncrement value GetAutoIncrement() bool // GetComment returns the comment value diff --git a/contracts/database/schema/grammar.go b/contracts/database/schema/grammar.go index f1a0744cc..72e938ada 100644 --- a/contracts/database/schema/grammar.go +++ b/contracts/database/schema/grammar.go @@ -37,18 +37,34 @@ type Grammar interface { GetAttributeCommands() []string // TypeBigInteger Create the column definition for a big integer type. TypeBigInteger(column ColumnDefinition) string + // TypeChar Create the column definition for a char type. + TypeChar(column ColumnDefinition) string // TypeDecimal Create the column definition for a decimal type. TypeDecimal(column ColumnDefinition) string // TypeDouble Create the column definition for a double type. TypeDouble(column ColumnDefinition) string + // TypeEnum Create the column definition for an enumeration type. + TypeEnum(column ColumnDefinition) string // TypeFloat Create the column definition for a float type. TypeFloat(column ColumnDefinition) string // TypeInteger Create the column definition for an integer type. TypeInteger(column ColumnDefinition) string + // TypeJson Create the column definition for a json type. + TypeJson(column ColumnDefinition) string + // TypeJsonb Create the column definition for a jsonb type. + TypeJsonb(column ColumnDefinition) string + // TypeLongText Create the column definition for a long text type. + TypeLongText(column ColumnDefinition) string // TypeMediumInteger Create the column definition for a medium integer type. TypeMediumInteger(column ColumnDefinition) string + // TypeMediumText Create the column definition for a medium text type. + TypeMediumText(column ColumnDefinition) string + // TypeText Create the column definition for a text type. + TypeText(column ColumnDefinition) string // TypeTinyInteger Create the column definition for a tiny integer type. TypeTinyInteger(column ColumnDefinition) string + // TypeTinyText Create the column definition for a tiny text type. + TypeTinyText(column ColumnDefinition) string // TypeSmallInteger Create the column definition for a small integer type. TypeSmallInteger(column ColumnDefinition) string // TypeString Create the column definition for a string type. diff --git a/database/schema/blueprint.go b/database/schema/blueprint.go index 34611c595..549f9d583 100644 --- a/database/schema/blueprint.go +++ b/database/schema/blueprint.go @@ -29,7 +29,7 @@ func (r *Blueprint) BigIncrements(column string) schema.ColumnDefinition { } func (r *Blueprint) BigInteger(column string) schema.ColumnDefinition { - return r.addIntegerColumn("bigInteger", column) + return r.createAndAddColumn("bigInteger", column) } func (r *Blueprint) Build(query ormcontract.Query, grammar schema.Grammar) error { @@ -42,6 +42,18 @@ func (r *Blueprint) Build(query ormcontract.Query, grammar schema.Grammar) error return nil } +func (r *Blueprint) Char(column string, length ...int) schema.ColumnDefinition { + defaultLength := constants.DefaultStringLength + if len(length) > 0 { + defaultLength = length[0] + } + + columnImpl := r.createAndAddColumn("char", column) + columnImpl.length = &defaultLength + + return columnImpl +} + func (r *Blueprint) Create() { r.addCommand(&schema.Command{ Name: constants.CommandCreate, @@ -49,23 +61,11 @@ func (r *Blueprint) Create() { } func (r *Blueprint) Decimal(column string) schema.ColumnDefinition { - columnImpl := &ColumnDefinition{ - name: &column, - ttype: convert.Pointer("decimal"), - } - r.addColumn(columnImpl) - - return columnImpl + return r.createAndAddColumn("decimal", column) } func (r *Blueprint) Double(column string) schema.ColumnDefinition { - columnImpl := &ColumnDefinition{ - name: &column, - ttype: convert.Pointer("double"), - } - r.addColumn(columnImpl) - - return columnImpl + return r.createAndAddColumn("double", column) } func (r *Blueprint) DropIfExists() { @@ -74,16 +74,20 @@ func (r *Blueprint) DropIfExists() { }) } +func (r *Blueprint) Enum(column string, allowed []string) schema.ColumnDefinition { + columnImpl := r.createAndAddColumn("enum", column) + columnImpl.allowed = allowed + + return columnImpl +} + func (r *Blueprint) Float(column string, precision ...int) schema.ColumnDefinition { - columnImpl := &ColumnDefinition{ - name: &column, - precision: convert.Pointer(53), - ttype: convert.Pointer("float"), - } + columnImpl := r.createAndAddColumn("float", column) + columnImpl.precision = convert.Pointer(53) + if len(precision) > 0 { columnImpl.precision = &precision[0] } - r.addColumn(columnImpl) return columnImpl } @@ -141,19 +145,35 @@ func (r *Blueprint) Index(column ...string) schema.IndexDefinition { } func (r *Blueprint) Integer(column string) schema.ColumnDefinition { - return r.addIntegerColumn("integer", column) + return r.createAndAddColumn("integer", column) } func (r *Blueprint) IntegerIncrements(column string) schema.ColumnDefinition { return r.UnsignedInteger(column).AutoIncrement() } +func (r *Blueprint) Json(column string) schema.ColumnDefinition { + return r.createAndAddColumn("json", column) +} + +func (r *Blueprint) Jsonb(column string) schema.ColumnDefinition { + return r.createAndAddColumn("jsonb", column) +} + +func (r *Blueprint) LongText(column string) schema.ColumnDefinition { + return r.createAndAddColumn("longText", column) +} + func (r *Blueprint) MediumIncrements(column string) schema.ColumnDefinition { return r.UnsignedMediumInteger(column).AutoIncrement() } func (r *Blueprint) MediumInteger(column string) schema.ColumnDefinition { - return r.addIntegerColumn("mediumInteger", column) + return r.createAndAddColumn("mediumInteger", column) +} + +func (r *Blueprint) MediumText(column string) schema.ColumnDefinition { + return r.createAndAddColumn("mediumText", column) } func (r *Blueprint) Primary(columns ...string) { @@ -169,7 +189,7 @@ func (r *Blueprint) SmallIncrements(column string) schema.ColumnDefinition { } func (r *Blueprint) SmallInteger(column string) schema.ColumnDefinition { - return r.addIntegerColumn("smallInteger", column) + return r.createAndAddColumn("smallInteger", column) } func (r *Blueprint) String(column string, length ...int) schema.ColumnDefinition { @@ -178,22 +198,26 @@ func (r *Blueprint) String(column string, length ...int) schema.ColumnDefinition defaultLength = length[0] } - columnImpl := &ColumnDefinition{ - length: &defaultLength, - name: &column, - ttype: convert.Pointer("string"), - } - r.addColumn(columnImpl) + columnImpl := r.createAndAddColumn("string", column) + columnImpl.length = &defaultLength return columnImpl } +func (r *Blueprint) Text(column string) schema.ColumnDefinition { + return r.createAndAddColumn("text", column) +} + func (r *Blueprint) TinyIncrements(column string) schema.ColumnDefinition { return r.UnsignedTinyInteger(column).AutoIncrement() } func (r *Blueprint) TinyInteger(column string) schema.ColumnDefinition { - return r.addIntegerColumn("tinyInteger", column) + return r.createAndAddColumn("tinyInteger", column) +} + +func (r *Blueprint) TinyText(column string) schema.ColumnDefinition { + return r.createAndAddColumn("tinyText", column) } func (r *Blueprint) ToSql(grammar schema.Grammar) []string { @@ -262,17 +286,6 @@ func (r *Blueprint) addAttributeCommands(grammar schema.Grammar) { } } -func (r *Blueprint) addColumn(column *ColumnDefinition) { - r.columns = append(r.columns, column) - - if !r.isCreate() { - r.addCommand(&schema.Command{ - Name: constants.CommandAdd, - Column: column, - }) - } -} - func (r *Blueprint) addCommand(command *schema.Command) { r.commands = append(r.commands, command) } @@ -281,13 +294,20 @@ func (r *Blueprint) addImpliedCommands(grammar schema.Grammar) { r.addAttributeCommands(grammar) } -func (r *Blueprint) addIntegerColumn(name, column string) schema.ColumnDefinition { +func (r *Blueprint) createAndAddColumn(ttype, name string) *ColumnDefinition { columnImpl := &ColumnDefinition{ - name: &column, - ttype: convert.Pointer(name), + name: &name, + ttype: convert.Pointer(ttype), } - r.addColumn(columnImpl) + r.columns = append(r.columns, columnImpl) + + if !r.isCreate() { + r.addCommand(&schema.Command{ + Name: constants.CommandAdd, + Column: columnImpl, + }) + } return columnImpl } diff --git a/database/schema/blueprint_test.go b/database/schema/blueprint_test.go index 62c5869e5..e0c468fa5 100644 --- a/database/schema/blueprint_test.go +++ b/database/schema/blueprint_test.go @@ -136,6 +136,26 @@ func (s *BlueprintTestSuite) TestBuild() { } } +func (s *BlueprintTestSuite) TestChar() { + column := "name" + customLength := 100 + length := constants.DefaultStringLength + ttype := "char" + s.blueprint.Char(column) + s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ + length: &length, + name: &column, + ttype: &ttype, + }) + + s.blueprint.Char(column, customLength) + s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ + length: &customLength, + name: &column, + ttype: &ttype, + }) +} + func (s *BlueprintTestSuite) TestCreateIndexName() { name := s.blueprint.createIndexName("index", []string{"id", "name-1", "name.2"}) s.Equal("goravel_users_id_name_1_name_2_index", name) diff --git a/database/schema/column.go b/database/schema/column.go index cc95588bc..5c2a93240 100644 --- a/database/schema/column.go +++ b/database/schema/column.go @@ -6,6 +6,7 @@ import ( ) type ColumnDefinition struct { + allowed []string autoIncrement *bool comment *string def any @@ -31,6 +32,10 @@ func (r *ColumnDefinition) Comment(comment string) schema.ColumnDefinition { return r } +func (r *ColumnDefinition) GetAllowed() []string { + return r.allowed +} + func (r *ColumnDefinition) GetAutoIncrement() (autoIncrement bool) { if r.autoIncrement != nil { return *r.autoIncrement diff --git a/database/schema/grammars/mysql.go b/database/schema/grammars/mysql.go index b938907cf..3cdc869ae 100644 --- a/database/schema/grammars/mysql.go +++ b/database/schema/grammars/mysql.go @@ -210,6 +210,10 @@ func (r *Mysql) TypeBigInteger(column schema.ColumnDefinition) string { return "bigint" } +func (r *Mysql) TypeChar(column schema.ColumnDefinition) string { + return fmt.Sprintf("char(%d)", column.GetLength()) +} + func (r *Mysql) TypeDecimal(column schema.ColumnDefinition) string { return fmt.Sprintf("decimal(%d, %d)", column.GetTotal(), column.GetPlaces()) } @@ -218,6 +222,10 @@ func (r *Mysql) TypeDouble(column schema.ColumnDefinition) string { return "double" } +func (r *Mysql) TypeEnum(column schema.ColumnDefinition) string { + return fmt.Sprintf(`enum(%s)`, strings.Join(r.wrap.Quotes(column.GetAllowed()), ", ")) +} + func (r *Mysql) TypeFloat(column schema.ColumnDefinition) string { precision := column.GetPrecision() if precision > 0 { @@ -231,12 +239,28 @@ func (r *Mysql) TypeInteger(column schema.ColumnDefinition) string { return "int" } +func (r *Mysql) TypeJson(column schema.ColumnDefinition) string { + return "json" +} + +func (r *Mysql) TypeJsonb(column schema.ColumnDefinition) string { + return "json" +} + +func (r *Mysql) TypeLongText(column schema.ColumnDefinition) string { + return "longtext" +} + func (r *Mysql) TypeMediumInteger(column schema.ColumnDefinition) string { return "mediumint" } -func (r *Mysql) TypeTinyInteger(column schema.ColumnDefinition) string { - return "tinyint" +func (r *Mysql) TypeMediumText(column schema.ColumnDefinition) string { + return "mediumtext" +} + +func (r *Mysql) TypeText(column schema.ColumnDefinition) string { + return "text" } func (r *Mysql) TypeSmallInteger(column schema.ColumnDefinition) string { @@ -252,6 +276,14 @@ func (r *Mysql) TypeString(column schema.ColumnDefinition) string { return "varchar(255)" } +func (r *Mysql) TypeTinyInteger(column schema.ColumnDefinition) string { + return "tinyint" +} + +func (r *Mysql) TypeTinyText(column schema.ColumnDefinition) string { + return "tinytext" +} + func (r *Mysql) getColumns(blueprint schema.Blueprint) []string { var columns []string for _, column := range blueprint.GetAddedColumns() { diff --git a/database/schema/grammars/mysql_test.go b/database/schema/grammars/mysql_test.go index 1bfba17e1..76d917351 100644 --- a/database/schema/grammars/mysql_test.go +++ b/database/schema/grammars/mysql_test.go @@ -305,6 +305,13 @@ func (s *MysqlSuite) TestTypeDecimal() { s.Equal("decimal(4, 2)", s.grammar.TypeDecimal(mockColumn)) } +func (s *MysqlSuite) TestTypeEnum() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetAllowed().Return([]string{"a", "b"}).Once() + + s.Equal(`enum('a', 'b')`, s.grammar.TypeEnum(mockColumn)) +} + func (s *MysqlSuite) TestTypeFloat() { mockColumn := mocksschema.NewColumnDefinition(s.T()) mockColumn.EXPECT().GetPrecision().Return(0).Once() diff --git a/database/schema/grammars/postgres.go b/database/schema/grammars/postgres.go index 1a11741bc..cdfff45ba 100644 --- a/database/schema/grammars/postgres.go +++ b/database/schema/grammars/postgres.go @@ -212,6 +212,15 @@ func (r *Postgres) TypeBigInteger(column schema.ColumnDefinition) string { return "bigint" } +func (r *Postgres) TypeChar(column schema.ColumnDefinition) string { + length := column.GetLength() + if length > 0 { + return fmt.Sprintf("char(%d)", length) + } + + return "char" +} + func (r *Postgres) TypeDecimal(column schema.ColumnDefinition) string { return fmt.Sprintf("decimal(%d, %d)", column.GetTotal(), column.GetPlaces()) } @@ -220,6 +229,10 @@ func (r *Postgres) TypeDouble(column schema.ColumnDefinition) string { return "double precision" } +func (r *Postgres) TypeEnum(column schema.ColumnDefinition) string { + return fmt.Sprintf(`varchar(255) check ("%s" in (%s))`, column.GetName(), strings.Join(r.wrap.Quotes(column.GetAllowed()), ", ")) +} + func (r *Postgres) TypeFloat(column schema.ColumnDefinition) string { precision := column.GetPrecision() if precision > 0 { @@ -237,10 +250,30 @@ func (r *Postgres) TypeInteger(column schema.ColumnDefinition) string { return "integer" } +func (r *Postgres) TypeJson(column schema.ColumnDefinition) string { + return "json" +} + +func (r *Postgres) TypeJsonb(column schema.ColumnDefinition) string { + return "jsonb" +} + +func (r *Postgres) TypeLongText(column schema.ColumnDefinition) string { + return "text" +} + func (r *Postgres) TypeMediumInteger(column schema.ColumnDefinition) string { return r.TypeInteger(column) } +func (r *Postgres) TypeMediumText(column schema.ColumnDefinition) string { + return "text" +} + +func (r *Postgres) TypeText(column schema.ColumnDefinition) string { + return "text" +} + func (r *Postgres) TypeSmallInteger(column schema.ColumnDefinition) string { if column.GetAutoIncrement() { return "smallserial" @@ -249,10 +282,6 @@ func (r *Postgres) TypeSmallInteger(column schema.ColumnDefinition) string { return "smallint" } -func (r *Postgres) TypeTinyInteger(column schema.ColumnDefinition) string { - return r.TypeSmallInteger(column) -} - func (r *Postgres) TypeString(column schema.ColumnDefinition) string { length := column.GetLength() if length > 0 { @@ -262,6 +291,14 @@ func (r *Postgres) TypeString(column schema.ColumnDefinition) string { return "varchar" } +func (r *Postgres) TypeTinyInteger(column schema.ColumnDefinition) string { + return r.TypeSmallInteger(column) +} + +func (r *Postgres) TypeTinyText(column schema.ColumnDefinition) string { + return "varchar(255)" +} + func (r *Postgres) getColumns(blueprint schema.Blueprint) []string { var columns []string for _, column := range blueprint.GetAddedColumns() { diff --git a/database/schema/grammars/postgres_test.go b/database/schema/grammars/postgres_test.go index 265a8a260..d08b9e482 100644 --- a/database/schema/grammars/postgres_test.go +++ b/database/schema/grammars/postgres_test.go @@ -348,6 +348,14 @@ func (s *PostgresSuite) TestTypeDecimal() { s.Equal("decimal(4, 2)", s.grammar.TypeDecimal(mockColumn)) } +func (s *PostgresSuite) TestTypeEnum() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetName().Return("a").Once() + mockColumn.EXPECT().GetAllowed().Return([]string{"a", "b"}).Once() + + s.Equal(`varchar(255) check ("a" in ('a', 'b'))`, s.grammar.TypeEnum(mockColumn)) +} + func (s *PostgresSuite) TestTypeFloat() { mockColumn := mocksschema.NewColumnDefinition(s.T()) mockColumn.EXPECT().GetPrecision().Return(0).Once() diff --git a/database/schema/grammars/sqlite.go b/database/schema/grammars/sqlite.go index 8c156e4ac..881ebb6b9 100644 --- a/database/schema/grammars/sqlite.go +++ b/database/schema/grammars/sqlite.go @@ -165,6 +165,10 @@ func (r *Sqlite) TypeBigInteger(column schema.ColumnDefinition) string { return "integer" } +func (r *Sqlite) TypeChar(column schema.ColumnDefinition) string { + return "varchar" +} + func (r *Sqlite) TypeDecimal(column schema.ColumnDefinition) string { return "numeric" } @@ -173,6 +177,10 @@ func (r *Sqlite) TypeDouble(column schema.ColumnDefinition) string { return "double" } +func (r *Sqlite) TypeEnum(column schema.ColumnDefinition) string { + return fmt.Sprintf(`varchar check ("%s" in (%s))`, column.GetName(), strings.Join(r.wrap.Quotes(column.GetAllowed()), ", ")) +} + func (r *Sqlite) TypeFloat(column schema.ColumnDefinition) string { return "float" } @@ -181,14 +189,38 @@ func (r *Sqlite) TypeInteger(column schema.ColumnDefinition) string { return "integer" } +func (r *Sqlite) TypeJson(column schema.ColumnDefinition) string { + return "text" +} + +func (r *Sqlite) TypeJsonb(column schema.ColumnDefinition) string { + return "text" +} + +func (r *Sqlite) TypeLongText(column schema.ColumnDefinition) string { + return "text" +} + func (r *Sqlite) TypeMediumInteger(column schema.ColumnDefinition) string { return "integer" } +func (r *Sqlite) TypeMediumText(column schema.ColumnDefinition) string { + return "text" +} + +func (r *Sqlite) TypeText(column schema.ColumnDefinition) string { + return "text" +} + func (r *Sqlite) TypeTinyInteger(column schema.ColumnDefinition) string { return "integer" } +func (r *Sqlite) TypeTinyText(column schema.ColumnDefinition) string { + return "text" +} + func (r *Sqlite) TypeSmallInteger(column schema.ColumnDefinition) string { return "integer" } diff --git a/database/schema/grammars/sqlite_test.go b/database/schema/grammars/sqlite_test.go index 8dcf8231f..ef6f19635 100644 --- a/database/schema/grammars/sqlite_test.go +++ b/database/schema/grammars/sqlite_test.go @@ -225,3 +225,11 @@ func (s *SqliteSuite) TestModifyIncrement() { s.Equal(" primary key autoincrement", s.grammar.ModifyIncrement(mockBlueprint, mockColumn)) } + +func (s *SqliteSuite) TestTypeEnum() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetName().Return("a").Once() + mockColumn.EXPECT().GetAllowed().Return([]string{"a", "b"}).Once() + + s.Equal(`varchar check ("a" in ('a', 'b'))`, s.grammar.TypeEnum(mockColumn)) +} diff --git a/database/schema/grammars/sqlserver.go b/database/schema/grammars/sqlserver.go index 072e111ab..e902a090b 100644 --- a/database/schema/grammars/sqlserver.go +++ b/database/schema/grammars/sqlserver.go @@ -211,6 +211,10 @@ func (r *Sqlserver) TypeBigInteger(column schema.ColumnDefinition) string { return "bigint" } +func (r *Sqlserver) TypeChar(column schema.ColumnDefinition) string { + return fmt.Sprintf("nchar(%d)", column.GetLength()) +} + func (r *Sqlserver) TypeDecimal(column schema.ColumnDefinition) string { return fmt.Sprintf("decimal(%d, %d)", column.GetTotal(), column.GetPlaces()) } @@ -219,6 +223,10 @@ func (r *Sqlserver) TypeDouble(column schema.ColumnDefinition) string { return "double precision" } +func (r *Sqlserver) TypeEnum(column schema.ColumnDefinition) string { + return fmt.Sprintf(`nvarchar(255) check ("%s" in (%s))`, column.GetName(), strings.Join(r.wrap.Quotes(column.GetAllowed()), ", ")) +} + func (r *Sqlserver) TypeFloat(column schema.ColumnDefinition) string { precision := column.GetPrecision() if precision > 0 { @@ -232,12 +240,28 @@ func (r *Sqlserver) TypeInteger(column schema.ColumnDefinition) string { return "int" } +func (r *Sqlserver) TypeJson(column schema.ColumnDefinition) string { + return "nvarchar(max)" +} + +func (r *Sqlserver) TypeJsonb(column schema.ColumnDefinition) string { + return "nvarchar(max)" +} + +func (r *Sqlserver) TypeLongText(column schema.ColumnDefinition) string { + return "nvarchar(max)" +} + func (r *Sqlserver) TypeMediumInteger(column schema.ColumnDefinition) string { return "int" } -func (r *Sqlserver) TypeTinyInteger(column schema.ColumnDefinition) string { - return "tinyint" +func (r *Sqlserver) TypeMediumText(column schema.ColumnDefinition) string { + return "nvarchar(max)" +} + +func (r *Sqlserver) TypeText(column schema.ColumnDefinition) string { + return "nvarchar(max)" } func (r *Sqlserver) TypeSmallInteger(column schema.ColumnDefinition) string { @@ -253,6 +277,14 @@ func (r *Sqlserver) TypeString(column schema.ColumnDefinition) string { return "nvarchar(255)" } +func (r *Sqlserver) TypeTinyInteger(column schema.ColumnDefinition) string { + return "tinyint" +} + +func (r *Sqlserver) TypeTinyText(column schema.ColumnDefinition) string { + return "nvarchar(255)" +} + func (r *Sqlserver) getColumns(blueprint schema.Blueprint) []string { var columns []string for _, column := range blueprint.GetAddedColumns() { diff --git a/database/schema/grammars/sqlserver_test.go b/database/schema/grammars/sqlserver_test.go index 679fdd7d0..f0977e80a 100644 --- a/database/schema/grammars/sqlserver_test.go +++ b/database/schema/grammars/sqlserver_test.go @@ -284,6 +284,14 @@ func (s *SqlserverSuite) TestTypeDecimal() { s.Equal("decimal(4, 2)", s.grammar.TypeDecimal(mockColumn)) } +func (s *SqlserverSuite) TestTypeEnum() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetName().Return("a").Once() + mockColumn.EXPECT().GetAllowed().Return([]string{"a", "b"}).Once() + + s.Equal(`nvarchar(255) check ("a" in (N'a', N'b'))`, s.grammar.TypeEnum(mockColumn)) +} + func (s *SqlserverSuite) TestTypeFloat() { mockColumn := mocksschema.NewColumnDefinition(s.T()) mockColumn.EXPECT().GetPrecision().Return(0).Once() diff --git a/database/schema/grammars/wrap.go b/database/schema/grammars/wrap.go index f49d6d300..581102c94 100644 --- a/database/schema/grammars/wrap.go +++ b/database/schema/grammars/wrap.go @@ -5,6 +5,7 @@ import ( "strings" contractsdatabase "github.com/goravel/framework/contracts/database" + "github.com/goravel/framework/support/collect" ) type Wrap struct { @@ -49,6 +50,15 @@ func (r *Wrap) Quote(value string) string { return fmt.Sprintf("'%s'", value) } +func (r *Wrap) Quotes(value []string) []string { + return collect.Map(value, func(v string, _ int) string { + if r.driver == contractsdatabase.DriverSqlserver { + return "N" + r.Quote(v) + } + return r.Quote(v) + }) +} + func (r *Wrap) Segments(segments []string) string { for i, segment := range segments { if i == 0 && len(segments) > 1 { diff --git a/database/schema/grammars/wrap_test.go b/database/schema/grammars/wrap_test.go index 503e3953d..2a438e7f6 100644 --- a/database/schema/grammars/wrap_test.go +++ b/database/schema/grammars/wrap_test.go @@ -46,6 +46,15 @@ func (s *WrapTestSuite) TestQuoteWithEmptyValue() { s.Equal("", result) } +func (s *WrapTestSuite) TestQuotes() { + result := s.wrap.Quotes([]string{"value1", "value2"}) + s.Equal([]string{"'value1'", "'value2'"}, result) + + s.wrap.driver = database.DriverSqlserver + result = s.wrap.Quotes([]string{"value1", "value2"}) + s.Equal([]string{"N'value1'", "N'value2'"}, result) +} + func (s *WrapTestSuite) TestSegmentsWithMultipleSegments() { result := s.wrap.Segments([]string{"table", "column"}) s.Equal(`"prefix_table"."column"`, result) diff --git a/database/schema/schema_test.go b/database/schema/schema_test.go index e254a8841..3ed4c243c 100644 --- a/database/schema/schema_test.go +++ b/database/schema/schema_test.go @@ -81,15 +81,15 @@ func (s *SchemaSuite) TestColumnMethods_Postgres() { s.Equal("bigint", column.Type) s.Equal("int8", column.TypeName) } - //if column.Name == "char" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a char column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("character(255)", column.Type) - // s.Equal("bpchar", column.TypeName) - //} + if column.Name == "char" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a char column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("character(255)", column.Type) + s.Equal("bpchar", column.TypeName) + } //if column.Name == "date" { // s.False(column.Autoincrement) // s.Empty(column.Collation) @@ -135,15 +135,15 @@ func (s *SchemaSuite) TestColumnMethods_Postgres() { s.Equal("double precision", column.Type) s.Equal("float8", column.TypeName) } - //if column.Name == "enum" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a enum column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("character varying(255)", column.Type) - // s.Equal("varchar", column.TypeName) - //} + if column.Name == "enum" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a enum column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("character varying(255)", column.Type) + s.Equal("varchar", column.TypeName) + } if column.Name == "float" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -198,33 +198,60 @@ func (s *SchemaSuite) TestColumnMethods_Postgres() { s.Equal("character varying(255)", column.Type) s.Equal("varchar", column.TypeName) } - //if column.Name == "json" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a json column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("json", column.Type) - // s.Equal("json", column.TypeName) - //} - //if column.Name == "jsonb" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a jsonb column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("jsonb", column.Type) - // s.Equal("jsonb", column.TypeName) - //} - //if column.Name == "text" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a text column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("text", column.Type) - // s.Equal("text", column.TypeName) - //} + if column.Name == "json" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a json column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("json", column.Type) + s.Equal("json", column.TypeName) + } + if column.Name == "jsonb" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a jsonb column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("jsonb", column.Type) + s.Equal("jsonb", column.TypeName) + } + if column.Name == "text" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a text column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("text", column.Type) + s.Equal("text", column.TypeName) + } + if column.Name == "long_text" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a long_text column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("text", column.Type) + s.Equal("text", column.TypeName) + } + if column.Name == "medium_text" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a medium_text column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("text", column.Type) + s.Equal("text", column.TypeName) + } + if column.Name == "tiny_text" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a tiny_text column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("character varying(255)", column.Type) + s.Equal("varchar", column.TypeName) + } //if column.Name == "time" { // s.False(column.Autoincrement) // s.Empty(column.Collation) @@ -321,15 +348,13 @@ func (s *SchemaSuite) TestColumnMethods_Sqlite() { s.False(column.Nullable) s.Equal("integer", column.Type) } - //if column.Name == "char" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a char column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("character(255)", column.Type) - // s.Equal("bpchar", column.TypeName) - //} + if column.Name == "char" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("varchar", column.Type) + } //if column.Name == "date" { // s.False(column.Autoincrement) // s.Empty(column.Collation) @@ -371,15 +396,13 @@ func (s *SchemaSuite) TestColumnMethods_Sqlite() { s.False(column.Nullable) s.Equal("double", column.Type) } - //if column.Name == "enum" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a enum column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("character varying(255)", column.Type) - // s.Equal("varchar", column.TypeName) - //} + if column.Name == "enum" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("varchar", column.Type) + } if column.Name == "float" { s.False(column.Autoincrement) s.Empty(column.Comment) @@ -426,33 +449,48 @@ func (s *SchemaSuite) TestColumnMethods_Sqlite() { s.False(column.Nullable) s.Equal("varchar", column.Type) } - //if column.Name == "json" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a json column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("json", column.Type) - // s.Equal("json", column.TypeName) - //} - //if column.Name == "jsonb" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a jsonb column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("jsonb", column.Type) - // s.Equal("jsonb", column.TypeName) - //} - //if column.Name == "text" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a text column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("text", column.Type) - // s.Equal("text", column.TypeName) - //} + if column.Name == "json" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("text", column.Type) + } + if column.Name == "jsonb" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("text", column.Type) + } + if column.Name == "text" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("text", column.Type) + } + if column.Name == "long_text" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("text", column.Type) + } + if column.Name == "medium_text" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("text", column.Type) + } + if column.Name == "tiny_text" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("text", column.Type) + } //if column.Name == "time" { // s.False(column.Autoincrement) // s.Empty(column.Collation) @@ -547,15 +585,15 @@ func (s *SchemaSuite) TestColumnMethods_Mysql() { s.Equal("bigint", column.Type) s.Equal("bigint", column.TypeName) } - //if column.Name == "char" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a char column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("character(255)", column.Type) - // s.Equal("bpchar", column.TypeName) - //} + if column.Name == "char" { + s.False(column.Autoincrement) + s.Equal("utf8mb4_0900_ai_ci", column.Collation) + s.Equal("This is a char column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("char(255)", column.Type) + s.Equal("char", column.TypeName) + } //if column.Name == "date" { // s.False(column.Autoincrement) // s.Empty(column.Collation) @@ -601,15 +639,15 @@ func (s *SchemaSuite) TestColumnMethods_Mysql() { s.Equal("double", column.Type) s.Equal("double", column.TypeName) } - //if column.Name == "enum" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a enum column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("character varying(255)", column.Type) - // s.Equal("varchar", column.TypeName) - //} + if column.Name == "enum" { + s.False(column.Autoincrement) + s.Equal("utf8mb4_0900_ai_ci", column.Collation) + s.Equal("This is a enum column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("enum('a','b','c')", column.Type) + s.Equal("enum", column.TypeName) + } if column.Name == "float" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -664,33 +702,60 @@ func (s *SchemaSuite) TestColumnMethods_Mysql() { s.Equal("varchar(255)", column.Type) s.Equal("varchar", column.TypeName) } - //if column.Name == "json" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a json column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("json", column.Type) - // s.Equal("json", column.TypeName) - //} - //if column.Name == "jsonb" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a jsonb column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("jsonb", column.Type) - // s.Equal("jsonb", column.TypeName) - //} - //if column.Name == "text" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a text column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("text", column.Type) - // s.Equal("text", column.TypeName) - //} + if column.Name == "json" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a json column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("json", column.Type) + s.Equal("json", column.TypeName) + } + if column.Name == "jsonb" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a jsonb column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("json", column.Type) + s.Equal("json", column.TypeName) + } + if column.Name == "text" { + s.False(column.Autoincrement) + s.Equal("utf8mb4_0900_ai_ci", column.Collation) + s.Equal("This is a text column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("text", column.Type) + s.Equal("text", column.TypeName) + } + if column.Name == "long_text" { + s.False(column.Autoincrement) + s.Equal("utf8mb4_0900_ai_ci", column.Collation) + s.Equal("This is a long_text column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("longtext", column.Type) + s.Equal("longtext", column.TypeName) + } + if column.Name == "medium_text" { + s.False(column.Autoincrement) + s.Equal("utf8mb4_0900_ai_ci", column.Collation) + s.Equal("This is a medium_text column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("mediumtext", column.Type) + s.Equal("mediumtext", column.TypeName) + } + if column.Name == "tiny_text" { + s.False(column.Autoincrement) + s.Equal("utf8mb4_0900_ai_ci", column.Collation) + s.Equal("This is a tiny_text column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("tinytext", column.Type) + s.Equal("tinytext", column.TypeName) + } //if column.Name == "time" { // s.False(column.Autoincrement) // s.Empty(column.Collation) @@ -789,15 +854,15 @@ func (s *SchemaSuite) TestColumnMethods_Sqlserver() { s.Equal("bigint", column.Type) s.Equal("bigint", column.TypeName) } - //if column.Name == "char" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("character(255)", column.Type) - // s.Equal("bpchar", column.TypeName) - //} + if column.Name == "char" { + s.False(column.Autoincrement) + s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("nchar(510)", column.Type) + s.Equal("nchar", column.TypeName) + } //if column.Name == "date" { // s.False(column.Autoincrement) // s.Empty(column.Collation) @@ -843,15 +908,15 @@ func (s *SchemaSuite) TestColumnMethods_Sqlserver() { s.Equal("float(53)", column.Type) s.Equal("float", column.TypeName) } - //if column.Name == "enum" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("character varying(255)", column.Type) - // s.Equal("varchar", column.TypeName) - //} + if column.Name == "enum" { + s.False(column.Autoincrement) + s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("nvarchar(510)", column.Type) + s.Equal("nvarchar", column.TypeName) + } if column.Name == "float" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -906,33 +971,60 @@ func (s *SchemaSuite) TestColumnMethods_Sqlserver() { s.Equal("nvarchar(510)", column.Type) s.Equal("nvarchar", column.TypeName) } - //if column.Name == "json" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("json", column.Type) - // s.Equal("json", column.TypeName) - //} - //if column.Name == "jsonb" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("jsonb", column.Type) - // s.Equal("jsonb", column.TypeName) - //} - //if column.Name == "text" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("text", column.Type) - // s.Equal("text", column.TypeName) - //} + if column.Name == "json" { + s.False(column.Autoincrement) + s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("nvarchar(max)", column.Type) + s.Equal("nvarchar", column.TypeName) + } + if column.Name == "jsonb" { + s.False(column.Autoincrement) + s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("nvarchar(max)", column.Type) + s.Equal("nvarchar", column.TypeName) + } + if column.Name == "text" { + s.False(column.Autoincrement) + s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("nvarchar(max)", column.Type) + s.Equal("nvarchar", column.TypeName) + } + if column.Name == "long_text" { + s.False(column.Autoincrement) + s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("nvarchar(max)", column.Type) + s.Equal("nvarchar", column.TypeName) + } + if column.Name == "medium_text" { + s.False(column.Autoincrement) + s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("nvarchar(max)", column.Type) + s.Equal("nvarchar", column.TypeName) + } + if column.Name == "tiny_text" { + s.False(column.Autoincrement) + s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("nvarchar(510)", column.Type) + s.Equal("nvarchar", column.TypeName) + } //if column.Name == "time" { // s.False(column.Autoincrement) // s.Empty(column.Collation) @@ -1538,22 +1630,25 @@ func (s *SchemaSuite) TestSql() { func (s *SchemaSuite) createTableAndAssertColumnsForColumnMethods(schema contractsschema.Schema, table string) { err := schema.Create(table, func(table contractsschema.Blueprint) { table.BigInteger("big_integer").Comment("This is a big_integer column") - //table.Char("char").Comment("This is a char column") + table.Char("char").Comment("This is a char column") //table.Date("date").Comment("This is a date column") //table.DateTime("date_time", 3).Comment("This is a date time column") //table.DateTimeTz("date_time_tz", 3).Comment("This is a date time with time zone column") table.Decimal("decimal").Places(1).Total(4).Comment("This is a decimal column") table.Double("double").Comment("This is a double column") - //table.Enum("enum", []string{"a", "b", "c"}).Comment("This is a enum column") + table.Enum("enum", []string{"a", "b", "c"}).Comment("This is a enum column") table.Float("float", 2).Comment("This is a float column") table.ID().Comment("This is a id column") table.Integer("integer").Comment("This is a integer column") //table.SoftDeletes() //table.SoftDeletesTz("another_deleted_at") table.String("string").Comment("This is a string column") - //table.Json("json").Comment("This is a json column") - //table.Jsonb("jsonb").Comment("This is a jsonb column") - //table.Text("text").Comment("This is a text column") + table.Json("json").Comment("This is a json column") + table.Jsonb("jsonb").Comment("This is a jsonb column") + table.Text("text").Comment("This is a text column") + table.LongText("long_text").Comment("This is a long_text column") + table.MediumText("medium_text").Comment("This is a medium_text column") + table.TinyText("tiny_text").Comment("This is a tiny_text column") //table.Time("time", 2).Comment("This is a time column") //table.TimeTz("time_tz", 2).Comment("This is a time with time zone column") //table.Timestamp("timestamp", 2).Comment("This is a timestamp without time zone column") @@ -1570,23 +1665,26 @@ func (s *SchemaSuite) createTableAndAssertColumnsForColumnMethods(schema contrac columnListing := schema.GetColumnListing(table) - s.Equal(9, len(columnListing)) + s.Equal(17, len(columnListing)) s.Contains(columnListing, "big_integer") - //s.Contains(columnListing, "char") + s.Contains(columnListing, "char") //s.Contains(columnListing, "date") //s.Contains(columnListing, "date_time") //s.Contains(columnListing, "date_time_tz") s.Contains(columnListing, "decimal") s.Contains(columnListing, "double") - //s.Contains(columnListing, "enum") + s.Contains(columnListing, "enum") s.Contains(columnListing, "id") s.Contains(columnListing, "integer") //s.Contains(columnListing, "deleted_at") //s.Contains(columnListing, "another_deleted_at") s.Contains(columnListing, "string") - //s.Contains(columnListing, "json") - //s.Contains(columnListing, "jsonb") - //s.Contains(columnListing, "text") + s.Contains(columnListing, "json") + s.Contains(columnListing, "jsonb") + s.Contains(columnListing, "text") + s.Contains(columnListing, "long_text") + s.Contains(columnListing, "medium_text") + s.Contains(columnListing, "tiny_text") //s.Contains(columnListing, "time") //s.Contains(columnListing, "time_tz") //s.Contains(columnListing, "timestamp") diff --git a/mocks/database/schema/Blueprint.go b/mocks/database/schema/Blueprint.go index 7446cde0e..708221df7 100644 --- a/mocks/database/schema/Blueprint.go +++ b/mocks/database/schema/Blueprint.go @@ -164,6 +164,69 @@ func (_c *Blueprint_Build_Call) RunAndReturn(run func(orm.Query, schema.Grammar) return _c } +// Char provides a mock function with given fields: column, length +func (_m *Blueprint) Char(column string, length ...int) schema.ColumnDefinition { + _va := make([]interface{}, len(length)) + for _i := range length { + _va[_i] = length[_i] + } + var _ca []interface{} + _ca = append(_ca, column) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Char") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string, ...int) schema.ColumnDefinition); ok { + r0 = rf(column, length...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_Char_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Char' +type Blueprint_Char_Call struct { + *mock.Call +} + +// Char is a helper method to define mock.On call +// - column string +// - length ...int +func (_e *Blueprint_Expecter) Char(column interface{}, length ...interface{}) *Blueprint_Char_Call { + return &Blueprint_Char_Call{Call: _e.mock.On("Char", + append([]interface{}{column}, length...)...)} +} + +func (_c *Blueprint_Char_Call) Run(run func(column string, length ...int)) *Blueprint_Char_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]int, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(int) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *Blueprint_Char_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_Char_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_Char_Call) RunAndReturn(run func(string, ...int) schema.ColumnDefinition) *Blueprint_Char_Call { + _c.Call.Return(run) + return _c +} + // Create provides a mock function with given fields: func (_m *Blueprint) Create() { _m.Called() @@ -324,6 +387,55 @@ func (_c *Blueprint_DropIfExists_Call) RunAndReturn(run func()) *Blueprint_DropI return _c } +// Enum provides a mock function with given fields: column, array +func (_m *Blueprint) Enum(column string, array []string) schema.ColumnDefinition { + ret := _m.Called(column, array) + + if len(ret) == 0 { + panic("no return value specified for Enum") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string, []string) schema.ColumnDefinition); ok { + r0 = rf(column, array) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_Enum_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Enum' +type Blueprint_Enum_Call struct { + *mock.Call +} + +// Enum is a helper method to define mock.On call +// - column string +// - array []string +func (_e *Blueprint_Expecter) Enum(column interface{}, array interface{}) *Blueprint_Enum_Call { + return &Blueprint_Enum_Call{Call: _e.mock.On("Enum", column, array)} +} + +func (_c *Blueprint_Enum_Call) Run(run func(column string, array []string)) *Blueprint_Enum_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].([]string)) + }) + return _c +} + +func (_c *Blueprint_Enum_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_Enum_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_Enum_Call) RunAndReturn(run func(string, []string) schema.ColumnDefinition) *Blueprint_Enum_Call { + _c.Call.Return(run) + return _c +} + // Float provides a mock function with given fields: column, precision func (_m *Blueprint) Float(column string, precision ...int) schema.ColumnDefinition { _va := make([]interface{}, len(precision)) @@ -899,6 +1011,150 @@ func (_c *Blueprint_IntegerIncrements_Call) RunAndReturn(run func(string) schema return _c } +// Json provides a mock function with given fields: column +func (_m *Blueprint) Json(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for Json") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string) schema.ColumnDefinition); ok { + r0 = rf(column) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_Json_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Json' +type Blueprint_Json_Call struct { + *mock.Call +} + +// Json is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) Json(column interface{}) *Blueprint_Json_Call { + return &Blueprint_Json_Call{Call: _e.mock.On("Json", column)} +} + +func (_c *Blueprint_Json_Call) Run(run func(column string)) *Blueprint_Json_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_Json_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_Json_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_Json_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_Json_Call { + _c.Call.Return(run) + return _c +} + +// Jsonb provides a mock function with given fields: column +func (_m *Blueprint) Jsonb(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for Jsonb") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string) schema.ColumnDefinition); ok { + r0 = rf(column) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_Jsonb_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Jsonb' +type Blueprint_Jsonb_Call struct { + *mock.Call +} + +// Jsonb is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) Jsonb(column interface{}) *Blueprint_Jsonb_Call { + return &Blueprint_Jsonb_Call{Call: _e.mock.On("Jsonb", column)} +} + +func (_c *Blueprint_Jsonb_Call) Run(run func(column string)) *Blueprint_Jsonb_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_Jsonb_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_Jsonb_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_Jsonb_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_Jsonb_Call { + _c.Call.Return(run) + return _c +} + +// LongText provides a mock function with given fields: column +func (_m *Blueprint) LongText(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for LongText") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string) schema.ColumnDefinition); ok { + r0 = rf(column) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_LongText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LongText' +type Blueprint_LongText_Call struct { + *mock.Call +} + +// LongText is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) LongText(column interface{}) *Blueprint_LongText_Call { + return &Blueprint_LongText_Call{Call: _e.mock.On("LongText", column)} +} + +func (_c *Blueprint_LongText_Call) Run(run func(column string)) *Blueprint_LongText_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_LongText_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_LongText_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_LongText_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_LongText_Call { + _c.Call.Return(run) + return _c +} + // MediumIncrements provides a mock function with given fields: column func (_m *Blueprint) MediumIncrements(column string) schema.ColumnDefinition { ret := _m.Called(column) @@ -995,6 +1251,54 @@ func (_c *Blueprint_MediumInteger_Call) RunAndReturn(run func(string) schema.Col return _c } +// MediumText provides a mock function with given fields: column +func (_m *Blueprint) MediumText(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for MediumText") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string) schema.ColumnDefinition); ok { + r0 = rf(column) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_MediumText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MediumText' +type Blueprint_MediumText_Call struct { + *mock.Call +} + +// MediumText is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) MediumText(column interface{}) *Blueprint_MediumText_Call { + return &Blueprint_MediumText_Call{Call: _e.mock.On("MediumText", column)} +} + +func (_c *Blueprint_MediumText_Call) Run(run func(column string)) *Blueprint_MediumText_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_MediumText_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_MediumText_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_MediumText_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_MediumText_Call { + _c.Call.Return(run) + return _c +} + // Primary provides a mock function with given fields: column func (_m *Blueprint) Primary(column ...string) { _va := make([]interface{}, len(column)) @@ -1233,6 +1537,54 @@ func (_c *Blueprint_String_Call) RunAndReturn(run func(string, ...int) schema.Co return _c } +// Text provides a mock function with given fields: column +func (_m *Blueprint) Text(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for Text") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string) schema.ColumnDefinition); ok { + r0 = rf(column) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_Text_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Text' +type Blueprint_Text_Call struct { + *mock.Call +} + +// Text is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) Text(column interface{}) *Blueprint_Text_Call { + return &Blueprint_Text_Call{Call: _e.mock.On("Text", column)} +} + +func (_c *Blueprint_Text_Call) Run(run func(column string)) *Blueprint_Text_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_Text_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_Text_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_Text_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_Text_Call { + _c.Call.Return(run) + return _c +} + // TinyIncrements provides a mock function with given fields: column func (_m *Blueprint) TinyIncrements(column string) schema.ColumnDefinition { ret := _m.Called(column) @@ -1329,6 +1681,54 @@ func (_c *Blueprint_TinyInteger_Call) RunAndReturn(run func(string) schema.Colum return _c } +// TinyText provides a mock function with given fields: column +func (_m *Blueprint) TinyText(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TinyText") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string) schema.ColumnDefinition); ok { + r0 = rf(column) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_TinyText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TinyText' +type Blueprint_TinyText_Call struct { + *mock.Call +} + +// TinyText is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) TinyText(column interface{}) *Blueprint_TinyText_Call { + return &Blueprint_TinyText_Call{Call: _e.mock.On("TinyText", column)} +} + +func (_c *Blueprint_TinyText_Call) Run(run func(column string)) *Blueprint_TinyText_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_TinyText_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_TinyText_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_TinyText_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_TinyText_Call { + _c.Call.Return(run) + return _c +} + // ToSql provides a mock function with given fields: grammar func (_m *Blueprint) ToSql(grammar schema.Grammar) []string { ret := _m.Called(grammar) diff --git a/mocks/database/schema/ColumnDefinition.go b/mocks/database/schema/ColumnDefinition.go index 1b695449d..653dc650c 100644 --- a/mocks/database/schema/ColumnDefinition.go +++ b/mocks/database/schema/ColumnDefinition.go @@ -115,6 +115,53 @@ func (_c *ColumnDefinition_Comment_Call) RunAndReturn(run func(string) schema.Co return _c } +// GetAllowed provides a mock function with given fields: +func (_m *ColumnDefinition) GetAllowed() []string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetAllowed") + } + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// ColumnDefinition_GetAllowed_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllowed' +type ColumnDefinition_GetAllowed_Call struct { + *mock.Call +} + +// GetAllowed is a helper method to define mock.On call +func (_e *ColumnDefinition_Expecter) GetAllowed() *ColumnDefinition_GetAllowed_Call { + return &ColumnDefinition_GetAllowed_Call{Call: _e.mock.On("GetAllowed")} +} + +func (_c *ColumnDefinition_GetAllowed_Call) Run(run func()) *ColumnDefinition_GetAllowed_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ColumnDefinition_GetAllowed_Call) Return(_a0 []string) *ColumnDefinition_GetAllowed_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ColumnDefinition_GetAllowed_Call) RunAndReturn(run func() []string) *ColumnDefinition_GetAllowed_Call { + _c.Call.Return(run) + return _c +} + // GetAutoIncrement provides a mock function with given fields: func (_m *ColumnDefinition) GetAutoIncrement() bool { ret := _m.Called() diff --git a/mocks/database/schema/Grammar.go b/mocks/database/schema/Grammar.go index aa4f241cb..2bb626a7e 100644 --- a/mocks/database/schema/Grammar.go +++ b/mocks/database/schema/Grammar.go @@ -855,6 +855,52 @@ func (_c *Grammar_TypeBigInteger_Call) RunAndReturn(run func(schema.ColumnDefini return _c } +// TypeChar provides a mock function with given fields: column +func (_m *Grammar) TypeChar(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeChar") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeChar_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeChar' +type Grammar_TypeChar_Call struct { + *mock.Call +} + +// TypeChar is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeChar(column interface{}) *Grammar_TypeChar_Call { + return &Grammar_TypeChar_Call{Call: _e.mock.On("TypeChar", column)} +} + +func (_c *Grammar_TypeChar_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeChar_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeChar_Call) Return(_a0 string) *Grammar_TypeChar_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeChar_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeChar_Call { + _c.Call.Return(run) + return _c +} + // TypeDecimal provides a mock function with given fields: column func (_m *Grammar) TypeDecimal(column schema.ColumnDefinition) string { ret := _m.Called(column) @@ -947,6 +993,52 @@ func (_c *Grammar_TypeDouble_Call) RunAndReturn(run func(schema.ColumnDefinition return _c } +// TypeEnum provides a mock function with given fields: column +func (_m *Grammar) TypeEnum(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeEnum") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeEnum_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeEnum' +type Grammar_TypeEnum_Call struct { + *mock.Call +} + +// TypeEnum is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeEnum(column interface{}) *Grammar_TypeEnum_Call { + return &Grammar_TypeEnum_Call{Call: _e.mock.On("TypeEnum", column)} +} + +func (_c *Grammar_TypeEnum_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeEnum_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeEnum_Call) Return(_a0 string) *Grammar_TypeEnum_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeEnum_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeEnum_Call { + _c.Call.Return(run) + return _c +} + // TypeFloat provides a mock function with given fields: column func (_m *Grammar) TypeFloat(column schema.ColumnDefinition) string { ret := _m.Called(column) @@ -1039,6 +1131,144 @@ func (_c *Grammar_TypeInteger_Call) RunAndReturn(run func(schema.ColumnDefinitio return _c } +// TypeJson provides a mock function with given fields: column +func (_m *Grammar) TypeJson(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeJson") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeJson_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeJson' +type Grammar_TypeJson_Call struct { + *mock.Call +} + +// TypeJson is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeJson(column interface{}) *Grammar_TypeJson_Call { + return &Grammar_TypeJson_Call{Call: _e.mock.On("TypeJson", column)} +} + +func (_c *Grammar_TypeJson_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeJson_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeJson_Call) Return(_a0 string) *Grammar_TypeJson_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeJson_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeJson_Call { + _c.Call.Return(run) + return _c +} + +// TypeJsonb provides a mock function with given fields: column +func (_m *Grammar) TypeJsonb(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeJsonb") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeJsonb_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeJsonb' +type Grammar_TypeJsonb_Call struct { + *mock.Call +} + +// TypeJsonb is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeJsonb(column interface{}) *Grammar_TypeJsonb_Call { + return &Grammar_TypeJsonb_Call{Call: _e.mock.On("TypeJsonb", column)} +} + +func (_c *Grammar_TypeJsonb_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeJsonb_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeJsonb_Call) Return(_a0 string) *Grammar_TypeJsonb_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeJsonb_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeJsonb_Call { + _c.Call.Return(run) + return _c +} + +// TypeLongText provides a mock function with given fields: column +func (_m *Grammar) TypeLongText(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeLongText") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeLongText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeLongText' +type Grammar_TypeLongText_Call struct { + *mock.Call +} + +// TypeLongText is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeLongText(column interface{}) *Grammar_TypeLongText_Call { + return &Grammar_TypeLongText_Call{Call: _e.mock.On("TypeLongText", column)} +} + +func (_c *Grammar_TypeLongText_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeLongText_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeLongText_Call) Return(_a0 string) *Grammar_TypeLongText_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeLongText_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeLongText_Call { + _c.Call.Return(run) + return _c +} + // TypeMediumInteger provides a mock function with given fields: column func (_m *Grammar) TypeMediumInteger(column schema.ColumnDefinition) string { ret := _m.Called(column) @@ -1085,6 +1315,52 @@ func (_c *Grammar_TypeMediumInteger_Call) RunAndReturn(run func(schema.ColumnDef return _c } +// TypeMediumText provides a mock function with given fields: column +func (_m *Grammar) TypeMediumText(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeMediumText") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeMediumText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeMediumText' +type Grammar_TypeMediumText_Call struct { + *mock.Call +} + +// TypeMediumText is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeMediumText(column interface{}) *Grammar_TypeMediumText_Call { + return &Grammar_TypeMediumText_Call{Call: _e.mock.On("TypeMediumText", column)} +} + +func (_c *Grammar_TypeMediumText_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeMediumText_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeMediumText_Call) Return(_a0 string) *Grammar_TypeMediumText_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeMediumText_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeMediumText_Call { + _c.Call.Return(run) + return _c +} + // TypeSmallInteger provides a mock function with given fields: column func (_m *Grammar) TypeSmallInteger(column schema.ColumnDefinition) string { ret := _m.Called(column) @@ -1177,6 +1453,52 @@ func (_c *Grammar_TypeString_Call) RunAndReturn(run func(schema.ColumnDefinition return _c } +// TypeText provides a mock function with given fields: column +func (_m *Grammar) TypeText(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeText") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeText' +type Grammar_TypeText_Call struct { + *mock.Call +} + +// TypeText is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeText(column interface{}) *Grammar_TypeText_Call { + return &Grammar_TypeText_Call{Call: _e.mock.On("TypeText", column)} +} + +func (_c *Grammar_TypeText_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeText_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeText_Call) Return(_a0 string) *Grammar_TypeText_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeText_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeText_Call { + _c.Call.Return(run) + return _c +} + // TypeTinyInteger provides a mock function with given fields: column func (_m *Grammar) TypeTinyInteger(column schema.ColumnDefinition) string { ret := _m.Called(column) @@ -1223,6 +1545,52 @@ func (_c *Grammar_TypeTinyInteger_Call) RunAndReturn(run func(schema.ColumnDefin return _c } +// TypeTinyText provides a mock function with given fields: column +func (_m *Grammar) TypeTinyText(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeTinyText") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeTinyText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeTinyText' +type Grammar_TypeTinyText_Call struct { + *mock.Call +} + +// TypeTinyText is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeTinyText(column interface{}) *Grammar_TypeTinyText_Call { + return &Grammar_TypeTinyText_Call{Call: _e.mock.On("TypeTinyText", column)} +} + +func (_c *Grammar_TypeTinyText_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeTinyText_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeTinyText_Call) Return(_a0 string) *Grammar_TypeTinyText_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeTinyText_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeTinyText_Call { + _c.Call.Return(run) + return _c +} + // NewGrammar creates a new instance of Grammar. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewGrammar(t interface {