From fb00d2f90f4073cbe244637a90bf06b20169eae3 Mon Sep 17 00:00:00 2001 From: Wenbo Han Date: Tue, 19 Nov 2024 09:25:44 +0800 Subject: [PATCH] feat: [#280] Add integer methods (#727) * feat: [#280] Add integer methods * chore: update mocks * optimize * chore: update mocks * optimize * chore: update mocks * optimize * Add test cases * Optimize test cases --------- Co-authored-by: hwbrzzl --- contracts/database/schema/blueprint.go | 24 + contracts/database/schema/column.go | 6 + contracts/database/schema/grammar.go | 12 + database/schema/blueprint.go | 73 ++- database/schema/blueprint_test.go | 107 +++- database/schema/column.go | 27 + database/schema/grammars/mysql.go | 29 ++ database/schema/grammars/mysql_test.go | 19 + database/schema/grammars/postgres.go | 33 ++ database/schema/grammars/postgres_test.go | 19 + database/schema/grammars/sqlite.go | 24 + database/schema/grammars/sqlserver.go | 29 ++ database/schema/grammars/sqlserver_test.go | 19 + database/schema/postgres_schema.go | 3 +- mocks/database/schema/Blueprint.go | 576 +++++++++++++++++++++ mocks/database/schema/ColumnDefinition.go | 135 +++++ mocks/database/schema/Grammar.go | 275 ++++++++++ 17 files changed, 1393 insertions(+), 17 deletions(-) diff --git a/contracts/database/schema/blueprint.go b/contracts/database/schema/blueprint.go index 7acc54c0a..9aa0b00d7 100644 --- a/contracts/database/schema/blueprint.go +++ b/contracts/database/schema/blueprint.go @@ -25,22 +25,46 @@ 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. + Increments(column string) ColumnDefinition // Index Specify an index for the table. Index(column ...string) IndexDefinition // Integer Create a new integer (4-byte) column on the table. Integer(column string) ColumnDefinition + // IntegerIncrements Create a new auto-incrementing integer (4-byte) column on the table. + IntegerIncrements(column string) ColumnDefinition // Primary Specify the primary key(s) for the table. Primary(column ...string) // SetTable Set the table that the blueprint operates on. SetTable(name string) + // SmallIncrements Create a new auto-incrementing small integer (2-byte) column on the table. + SmallIncrements(column string) ColumnDefinition + // SmallInteger Create a new small integer (2-byte) column on the table. + SmallInteger(column string) ColumnDefinition // String Create a new string column on the table. String(column string, length ...int) 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 // 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. UnsignedBigInteger(column string) ColumnDefinition + // UnsignedInteger Create a new unsigned integer (4-byte) column on the table. + UnsignedInteger(column string) ColumnDefinition + // UnsignedMediumInteger Create a new unsigned medium integer (3-byte) column on the table. + UnsignedMediumInteger(column string) ColumnDefinition + // UnsignedSmallInteger Create a new unsigned small integer (2-byte) column on the table. + UnsignedSmallInteger(column string) ColumnDefinition + // UnsignedTinyInteger Create a new unsigned tiny integer (1-byte) column on the table. + UnsignedTinyInteger(column string) ColumnDefinition } type IndexConfig struct { diff --git a/contracts/database/schema/column.go b/contracts/database/schema/column.go index 50960f82b..4e712c7af 100644 --- a/contracts/database/schema/column.go +++ b/contracts/database/schema/column.go @@ -13,6 +13,12 @@ type ColumnDefinition interface { GetName() string // GetNullable returns the nullable value GetNullable() bool + // GetPlaces returns the places value + GetPlaces() int + // GetPrecision returns the precision value + GetPrecision() int + // GetTotal returns the total value + GetTotal() int // GetType returns the type value GetType() string // Nullable allow NULL values to be inserted into the column diff --git a/contracts/database/schema/grammar.go b/contracts/database/schema/grammar.go index dc2644472..32d3485c4 100644 --- a/contracts/database/schema/grammar.go +++ b/contracts/database/schema/grammar.go @@ -33,8 +33,20 @@ type Grammar interface { GetAttributeCommands() []string // TypeBigInteger Create the column definition for a big integer type. TypeBigInteger(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() 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 + // TypeMediumInteger Create the column definition for a medium integer type. + TypeMediumInteger(column ColumnDefinition) string + // TypeTinyInteger Create the column definition for a tiny integer type. + TypeTinyInteger(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. TypeString(column ColumnDefinition) string } diff --git a/database/schema/blueprint.go b/database/schema/blueprint.go index db81f0cad..2c5c9b462 100644 --- a/database/schema/blueprint.go +++ b/database/schema/blueprint.go @@ -29,14 +29,7 @@ func (r *Blueprint) BigIncrements(column string) schema.ColumnDefinition { } func (r *Blueprint) BigInteger(column string) schema.ColumnDefinition { - columnImpl := &ColumnDefinition{ - name: &column, - ttype: convert.Pointer("bigInteger"), - } - - r.addColumn(columnImpl) - - return columnImpl + return r.addIntegerColumn("bigInteger", column) } func (r *Blueprint) Build(query ormcontract.Query, grammar schema.Grammar) error { @@ -95,6 +88,10 @@ func (r *Blueprint) HasCommand(command string) bool { return false } +func (r *Blueprint) MediumIncrements(column string) schema.ColumnDefinition { + return r.UnsignedMediumInteger(column).AutoIncrement() +} + func (r *Blueprint) ID(column ...string) schema.ColumnDefinition { if len(column) > 0 { return r.BigIncrements(column[0]) @@ -103,6 +100,10 @@ func (r *Blueprint) ID(column ...string) schema.ColumnDefinition { return r.BigIncrements("id") } +func (r *Blueprint) Increments(column string) schema.ColumnDefinition { + return r.IntegerIncrements(column) +} + func (r *Blueprint) Index(column ...string) schema.IndexDefinition { command := r.indexCommand(constants.CommandIndex, column) @@ -110,14 +111,15 @@ func (r *Blueprint) Index(column ...string) schema.IndexDefinition { } func (r *Blueprint) Integer(column string) schema.ColumnDefinition { - columnImpl := &ColumnDefinition{ - name: &column, - ttype: convert.Pointer("integer"), - } + return r.addIntegerColumn("integer", column) +} - r.addColumn(columnImpl) +func (r *Blueprint) IntegerIncrements(column string) schema.ColumnDefinition { + return r.UnsignedInteger(column).AutoIncrement() +} - return columnImpl +func (r *Blueprint) MediumInteger(column string) schema.ColumnDefinition { + return r.addIntegerColumn("mediumInteger", column) } func (r *Blueprint) Primary(columns ...string) { @@ -128,6 +130,14 @@ func (r *Blueprint) SetTable(name string) { r.table = name } +func (r *Blueprint) SmallIncrements(column string) schema.ColumnDefinition { + return r.UnsignedSmallInteger(column).AutoIncrement() +} + +func (r *Blueprint) SmallInteger(column string) schema.ColumnDefinition { + return r.addIntegerColumn("smallInteger", column) +} + func (r *Blueprint) String(column string, length ...int) schema.ColumnDefinition { defaultLength := constants.DefaultStringLength if len(length) > 0 { @@ -144,6 +154,14 @@ func (r *Blueprint) String(column string, length ...int) schema.ColumnDefinition return columnImpl } +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) +} + func (r *Blueprint) ToSql(grammar schema.Grammar) []string { r.addImpliedCommands(grammar) @@ -176,6 +194,22 @@ func (r *Blueprint) UnsignedBigInteger(column string) schema.ColumnDefinition { return r.BigInteger(column).Unsigned() } +func (r *Blueprint) UnsignedInteger(column string) schema.ColumnDefinition { + return r.Integer(column).Unsigned() +} + +func (r *Blueprint) UnsignedMediumInteger(column string) schema.ColumnDefinition { + return r.MediumInteger(column).Unsigned() +} + +func (r *Blueprint) UnsignedSmallInteger(column string) schema.ColumnDefinition { + return r.SmallInteger(column).Unsigned() +} + +func (r *Blueprint) UnsignedTinyInteger(column string) schema.ColumnDefinition { + return r.TinyInteger(column).Unsigned() +} + func (r *Blueprint) addAttributeCommands(grammar schema.Grammar) { attributeCommands := grammar.GetAttributeCommands() for _, column := range r.columns { @@ -209,6 +243,17 @@ func (r *Blueprint) addImpliedCommands(grammar schema.Grammar) { r.addAttributeCommands(grammar) } +func (r *Blueprint) addIntegerColumn(name, column string) schema.ColumnDefinition { + columnImpl := &ColumnDefinition{ + name: &column, + ttype: convert.Pointer(name), + } + + r.addColumn(columnImpl) + + return columnImpl +} + func (r *Blueprint) createIndexName(ttype string, columns []string) string { var table string if strings.Contains(r.table, ".") { diff --git a/database/schema/blueprint_test.go b/database/schema/blueprint_test.go index 531a195d7..8b5e90b3a 100644 --- a/database/schema/blueprint_test.go +++ b/database/schema/blueprint_test.go @@ -163,6 +163,17 @@ func (s *BlueprintTestSuite) TestHasCommand() { s.True(s.blueprint.HasCommand(constants.CommandCreate)) } +func (s *BlueprintTestSuite) TestIntegerIncrements() { + name := "name" + s.blueprint.IntegerIncrements(name) + s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ + autoIncrement: convert.Pointer(true), + name: &name, + unsigned: convert.Pointer(true), + ttype: convert.Pointer("integer"), + }) +} + func (s *BlueprintTestSuite) TestIndexCommand() { s.blueprint.indexCommand("index", []string{"id", "name"}) s.Contains(s.blueprint.commands, &schema.Command{ @@ -218,13 +229,45 @@ func (s *BlueprintTestSuite) TestInteger() { name: &name, ttype: convert.Pointer("integer"), }) +} - s.blueprint.Integer(name).AutoIncrement().Unsigned() +func (s *BlueprintTestSuite) TestMediumIncrements() { + name := "name" + s.blueprint.MediumIncrements(name) s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ autoIncrement: convert.Pointer(true), name: &name, unsigned: convert.Pointer(true), - ttype: convert.Pointer("integer"), + ttype: convert.Pointer("mediumInteger"), + }) +} + +func (s *BlueprintTestSuite) TestMediumInteger() { + name := "name" + s.blueprint.MediumInteger(name) + s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ + name: &name, + ttype: convert.Pointer("mediumInteger"), + }) +} + +func (s *BlueprintTestSuite) TestSmallIncrements() { + name := "name" + s.blueprint.SmallIncrements(name) + s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ + autoIncrement: convert.Pointer(true), + name: &name, + unsigned: convert.Pointer(true), + ttype: convert.Pointer("smallInteger"), + }) +} + +func (s *BlueprintTestSuite) TestSmallInteger() { + name := "name" + s.blueprint.SmallInteger(name) + s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ + name: &name, + ttype: convert.Pointer("smallInteger"), }) } @@ -248,6 +291,26 @@ func (s *BlueprintTestSuite) TestString() { }) } +func (s *BlueprintTestSuite) TestTinyIncrements() { + name := "name" + s.blueprint.TinyIncrements(name) + s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ + autoIncrement: convert.Pointer(true), + name: &name, + unsigned: convert.Pointer(true), + ttype: convert.Pointer("tinyInteger"), + }) +} + +func (s *BlueprintTestSuite) TestTinyInteger() { + name := "name" + s.blueprint.TinyInteger(name) + s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ + name: &name, + ttype: convert.Pointer("tinyInteger"), + }) +} + func (s *BlueprintTestSuite) TestToSql() { for driver, grammar := range s.grammars { // Create a table @@ -283,3 +346,43 @@ func (s *BlueprintTestSuite) TestUnsignedBigInteger() { unsigned: convert.Pointer(true), }) } + +func (s *BlueprintTestSuite) TestUnsignedInteger() { + name := "name" + s.blueprint.UnsignedInteger(name) + s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ + name: &name, + ttype: convert.Pointer("integer"), + unsigned: convert.Pointer(true), + }) +} + +func (s *BlueprintTestSuite) TestUnsignedMediumInteger() { + name := "name" + s.blueprint.UnsignedMediumInteger(name) + s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ + name: &name, + ttype: convert.Pointer("mediumInteger"), + unsigned: convert.Pointer(true), + }) +} + +func (s *BlueprintTestSuite) TestUnsignedSmallInteger() { + name := "name" + s.blueprint.UnsignedSmallInteger(name) + s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ + name: &name, + ttype: convert.Pointer("smallInteger"), + unsigned: convert.Pointer(true), + }) +} + +func (s *BlueprintTestSuite) TestUnsignedTinyInteger() { + name := "name" + s.blueprint.UnsignedTinyInteger(name) + s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{ + name: &name, + ttype: convert.Pointer("tinyInteger"), + unsigned: convert.Pointer(true), + }) +} diff --git a/database/schema/column.go b/database/schema/column.go index 87fdd9f61..2b4be4ef4 100644 --- a/database/schema/column.go +++ b/database/schema/column.go @@ -12,6 +12,9 @@ type ColumnDefinition struct { length *int name *string nullable *bool + places *int + precision *int + total *int ttype *string unsigned *bool } @@ -58,6 +61,30 @@ func (r *ColumnDefinition) GetNullable() bool { return false } +func (r *ColumnDefinition) GetPlaces() (places int) { + if r.places != nil { + return *r.places + } + + return 2 +} + +func (r *ColumnDefinition) GetPrecision() (precision int) { + if r.precision != nil { + return *r.precision + } + + return +} + +func (r *ColumnDefinition) GetTotal() (total int) { + if r.total != nil { + return *r.total + } + + return 8 +} + func (r *ColumnDefinition) GetType() (ttype string) { if r.ttype != nil { return *r.ttype diff --git a/database/schema/grammars/mysql.go b/database/schema/grammars/mysql.go index 3281ca547..7d9c968b7 100644 --- a/database/schema/grammars/mysql.go +++ b/database/schema/grammars/mysql.go @@ -184,10 +184,39 @@ func (r *Mysql) TypeBigInteger(column schema.ColumnDefinition) string { return "bigint" } +func (r *Mysql) TypeDecimal(column schema.ColumnDefinition) string { + return fmt.Sprintf("decimal(%d, %d)", column.GetTotal(), column.GetPlaces()) +} + +func (r *Mysql) TypeDouble() string { + return "double" +} + +func (r *Mysql) TypeFloat(column schema.ColumnDefinition) string { + precision := column.GetPrecision() + if precision > 0 { + return fmt.Sprintf("float(%d)", precision) + } + + return "float" +} + func (r *Mysql) TypeInteger(column schema.ColumnDefinition) string { return "int" } +func (r *Mysql) TypeMediumInteger(column schema.ColumnDefinition) string { + return "mediumint" +} + +func (r *Mysql) TypeTinyInteger(column schema.ColumnDefinition) string { + return "tinyint" +} + +func (r *Mysql) TypeSmallInteger(column schema.ColumnDefinition) string { + return "smallint" +} + func (r *Mysql) TypeString(column schema.ColumnDefinition) string { length := column.GetLength() if length > 0 { diff --git a/database/schema/grammars/mysql_test.go b/database/schema/grammars/mysql_test.go index 1ee5989a7..9cdafcb2f 100644 --- a/database/schema/grammars/mysql_test.go +++ b/database/schema/grammars/mysql_test.go @@ -292,6 +292,25 @@ func (s *MysqlSuite) TestModifyIncrement() { s.Equal(" auto_increment primary key", s.grammar.ModifyIncrement(mockBlueprint, mockColumn)) } +func (s *MysqlSuite) TestTypeDecimal() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetTotal().Return(4).Once() + mockColumn.EXPECT().GetPlaces().Return(2).Once() + + s.Equal("decimal(4, 2)", s.grammar.TypeDecimal(mockColumn)) +} + +func (s *MysqlSuite) TestTypeFloat() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetPrecision().Return(0).Once() + + s.Equal("float", s.grammar.TypeFloat(mockColumn)) + + mockColumn.EXPECT().GetPrecision().Return(2).Once() + + s.Equal("float(2)", s.grammar.TypeFloat(mockColumn)) +} + func (s *MysqlSuite) TestTypeString() { mockColumn1 := mocksschema.NewColumnDefinition(s.T()) mockColumn1.EXPECT().GetLength().Return(100).Once() diff --git a/database/schema/grammars/postgres.go b/database/schema/grammars/postgres.go index 3cab01978..a457d58e5 100644 --- a/database/schema/grammars/postgres.go +++ b/database/schema/grammars/postgres.go @@ -188,6 +188,23 @@ func (r *Postgres) TypeBigInteger(column schema.ColumnDefinition) string { return "bigint" } +func (r *Postgres) TypeDecimal(column schema.ColumnDefinition) string { + return fmt.Sprintf("decimal(%d, %d)", column.GetTotal(), column.GetPlaces()) +} + +func (r *Postgres) TypeDouble() string { + return "double precision" +} + +func (r *Postgres) TypeFloat(column schema.ColumnDefinition) string { + precision := column.GetPrecision() + if precision > 0 { + return fmt.Sprintf("float(%d)", precision) + } + + return "float" +} + func (r *Postgres) TypeInteger(column schema.ColumnDefinition) string { if column.GetAutoIncrement() { return "serial" @@ -196,6 +213,22 @@ func (r *Postgres) TypeInteger(column schema.ColumnDefinition) string { return "integer" } +func (r *Postgres) TypeMediumInteger(column schema.ColumnDefinition) string { + return r.TypeInteger(column) +} + +func (r *Postgres) TypeTinyInteger(column schema.ColumnDefinition) string { + return r.TypeSmallInteger(column) +} + +func (r *Postgres) TypeSmallInteger(column schema.ColumnDefinition) string { + if column.GetAutoIncrement() { + return "smallserial" + } + + return "smallint" +} + func (r *Postgres) TypeString(column schema.ColumnDefinition) string { length := column.GetLength() if length > 0 { diff --git a/database/schema/grammars/postgres_test.go b/database/schema/grammars/postgres_test.go index d7e6363b7..8364c68d9 100644 --- a/database/schema/grammars/postgres_test.go +++ b/database/schema/grammars/postgres_test.go @@ -325,6 +325,25 @@ func (s *PostgresSuite) TestTypeBigInteger() { s.Equal("bigint", s.grammar.TypeBigInteger(mockColumn2)) } +func (s *PostgresSuite) TestTypeDecimal() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetTotal().Return(4).Once() + mockColumn.EXPECT().GetPlaces().Return(2).Once() + + s.Equal("decimal(4, 2)", s.grammar.TypeDecimal(mockColumn)) +} + +func (s *PostgresSuite) TestTypeFloat() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetPrecision().Return(0).Once() + + s.Equal("float", s.grammar.TypeFloat(mockColumn)) + + mockColumn.EXPECT().GetPrecision().Return(2).Once() + + s.Equal("float(2)", s.grammar.TypeFloat(mockColumn)) +} + func (s *PostgresSuite) TestTypeInteger() { mockColumn1 := mocksschema.NewColumnDefinition(s.T()) mockColumn1.EXPECT().GetAutoIncrement().Return(true).Once() diff --git a/database/schema/grammars/sqlite.go b/database/schema/grammars/sqlite.go index 07228fdd7..e7c33d666 100644 --- a/database/schema/grammars/sqlite.go +++ b/database/schema/grammars/sqlite.go @@ -155,10 +155,34 @@ func (r *Sqlite) TypeBigInteger(column schema.ColumnDefinition) string { return "integer" } +func (r *Sqlite) TypeDecimal(column schema.ColumnDefinition) string { + return "numeric" +} + +func (r *Sqlite) TypeDouble() string { + return "double" +} + +func (r *Sqlite) TypeFloat(column schema.ColumnDefinition) string { + return "float" +} + func (r *Sqlite) TypeInteger(column schema.ColumnDefinition) string { return "integer" } +func (r *Sqlite) TypeMediumInteger(column schema.ColumnDefinition) string { + return "integer" +} + +func (r *Sqlite) TypeTinyInteger(column schema.ColumnDefinition) string { + return "integer" +} + +func (r *Sqlite) TypeSmallInteger(column schema.ColumnDefinition) string { + return "integer" +} + func (r *Sqlite) TypeString(column schema.ColumnDefinition) string { return "varchar" } diff --git a/database/schema/grammars/sqlserver.go b/database/schema/grammars/sqlserver.go index aeb812715..248cb3c3b 100644 --- a/database/schema/grammars/sqlserver.go +++ b/database/schema/grammars/sqlserver.go @@ -183,10 +183,39 @@ func (r *Sqlserver) TypeBigInteger(column schema.ColumnDefinition) string { return "bigint" } +func (r *Sqlserver) TypeDecimal(column schema.ColumnDefinition) string { + return fmt.Sprintf("decimal(%d, %d)", column.GetTotal(), column.GetPlaces()) +} + +func (r *Sqlserver) TypeDouble() string { + return "double precision" +} + +func (r *Sqlserver) TypeFloat(column schema.ColumnDefinition) string { + precision := column.GetPrecision() + if precision > 0 { + return fmt.Sprintf("float(%d)", precision) + } + + return "float" +} + func (r *Sqlserver) TypeInteger(column schema.ColumnDefinition) string { return "int" } +func (r *Sqlserver) TypeMediumInteger(column schema.ColumnDefinition) string { + return "int" +} + +func (r *Sqlserver) TypeTinyInteger(column schema.ColumnDefinition) string { + return "tinyint" +} + +func (r *Sqlserver) TypeSmallInteger(column schema.ColumnDefinition) string { + return "smallint" +} + func (r *Sqlserver) TypeString(column schema.ColumnDefinition) string { length := column.GetLength() if length > 0 { diff --git a/database/schema/grammars/sqlserver_test.go b/database/schema/grammars/sqlserver_test.go index 298af4a9a..679fdd7d0 100644 --- a/database/schema/grammars/sqlserver_test.go +++ b/database/schema/grammars/sqlserver_test.go @@ -276,6 +276,25 @@ func (s *SqlserverSuite) TestModifyIncrement() { s.Equal(" identity primary key", s.grammar.ModifyIncrement(mockBlueprint, mockColumn)) } +func (s *SqlserverSuite) TestTypeDecimal() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetTotal().Return(4).Once() + mockColumn.EXPECT().GetPlaces().Return(2).Once() + + s.Equal("decimal(4, 2)", s.grammar.TypeDecimal(mockColumn)) +} + +func (s *SqlserverSuite) TestTypeFloat() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetPrecision().Return(0).Once() + + s.Equal("float", s.grammar.TypeFloat(mockColumn)) + + mockColumn.EXPECT().GetPrecision().Return(2).Once() + + s.Equal("float(2)", s.grammar.TypeFloat(mockColumn)) +} + func (s *SqlserverSuite) TestTypeString() { mockColumn1 := mocksschema.NewColumnDefinition(s.T()) mockColumn1.EXPECT().GetLength().Return(100).Once() diff --git a/database/schema/postgres_schema.go b/database/schema/postgres_schema.go index 763fecb40..379b245a2 100644 --- a/database/schema/postgres_schema.go +++ b/database/schema/postgres_schema.go @@ -2,11 +2,12 @@ package schema import ( "fmt" + "slices" + "github.com/goravel/framework/contracts/database/orm" contractsschema "github.com/goravel/framework/contracts/database/schema" "github.com/goravel/framework/database/schema/grammars" "github.com/goravel/framework/database/schema/processors" - "slices" ) type PostgresSchema struct { diff --git a/mocks/database/schema/Blueprint.go b/mocks/database/schema/Blueprint.go index c4c6134bd..bea0a0a53 100644 --- a/mocks/database/schema/Blueprint.go +++ b/mocks/database/schema/Blueprint.go @@ -535,6 +535,54 @@ func (_c *Blueprint_ID_Call) RunAndReturn(run func(...string) schema.ColumnDefin return _c } +// Increments provides a mock function with given fields: column +func (_m *Blueprint) Increments(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for Increments") + } + + 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_Increments_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Increments' +type Blueprint_Increments_Call struct { + *mock.Call +} + +// Increments is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) Increments(column interface{}) *Blueprint_Increments_Call { + return &Blueprint_Increments_Call{Call: _e.mock.On("Increments", column)} +} + +func (_c *Blueprint_Increments_Call) Run(run func(column string)) *Blueprint_Increments_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_Increments_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_Increments_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_Increments_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_Increments_Call { + _c.Call.Return(run) + return _c +} + // Index provides a mock function with given fields: column func (_m *Blueprint) Index(column ...string) schema.IndexDefinition { _va := make([]interface{}, len(column)) @@ -644,6 +692,150 @@ func (_c *Blueprint_Integer_Call) RunAndReturn(run func(string) schema.ColumnDef return _c } +// IntegerIncrements provides a mock function with given fields: column +func (_m *Blueprint) IntegerIncrements(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for IntegerIncrements") + } + + 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_IntegerIncrements_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IntegerIncrements' +type Blueprint_IntegerIncrements_Call struct { + *mock.Call +} + +// IntegerIncrements is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) IntegerIncrements(column interface{}) *Blueprint_IntegerIncrements_Call { + return &Blueprint_IntegerIncrements_Call{Call: _e.mock.On("IntegerIncrements", column)} +} + +func (_c *Blueprint_IntegerIncrements_Call) Run(run func(column string)) *Blueprint_IntegerIncrements_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_IntegerIncrements_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_IntegerIncrements_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_IntegerIncrements_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_IntegerIncrements_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) + + if len(ret) == 0 { + panic("no return value specified for MediumIncrements") + } + + 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_MediumIncrements_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MediumIncrements' +type Blueprint_MediumIncrements_Call struct { + *mock.Call +} + +// MediumIncrements is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) MediumIncrements(column interface{}) *Blueprint_MediumIncrements_Call { + return &Blueprint_MediumIncrements_Call{Call: _e.mock.On("MediumIncrements", column)} +} + +func (_c *Blueprint_MediumIncrements_Call) Run(run func(column string)) *Blueprint_MediumIncrements_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_MediumIncrements_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_MediumIncrements_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_MediumIncrements_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_MediumIncrements_Call { + _c.Call.Return(run) + return _c +} + +// MediumInteger provides a mock function with given fields: column +func (_m *Blueprint) MediumInteger(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for MediumInteger") + } + + 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_MediumInteger_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MediumInteger' +type Blueprint_MediumInteger_Call struct { + *mock.Call +} + +// MediumInteger is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) MediumInteger(column interface{}) *Blueprint_MediumInteger_Call { + return &Blueprint_MediumInteger_Call{Call: _e.mock.On("MediumInteger", column)} +} + +func (_c *Blueprint_MediumInteger_Call) Run(run func(column string)) *Blueprint_MediumInteger_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_MediumInteger_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_MediumInteger_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_MediumInteger_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_MediumInteger_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)) @@ -723,6 +915,102 @@ func (_c *Blueprint_SetTable_Call) RunAndReturn(run func(string)) *Blueprint_Set return _c } +// SmallIncrements provides a mock function with given fields: column +func (_m *Blueprint) SmallIncrements(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for SmallIncrements") + } + + 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_SmallIncrements_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SmallIncrements' +type Blueprint_SmallIncrements_Call struct { + *mock.Call +} + +// SmallIncrements is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) SmallIncrements(column interface{}) *Blueprint_SmallIncrements_Call { + return &Blueprint_SmallIncrements_Call{Call: _e.mock.On("SmallIncrements", column)} +} + +func (_c *Blueprint_SmallIncrements_Call) Run(run func(column string)) *Blueprint_SmallIncrements_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_SmallIncrements_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_SmallIncrements_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_SmallIncrements_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_SmallIncrements_Call { + _c.Call.Return(run) + return _c +} + +// SmallInteger provides a mock function with given fields: column +func (_m *Blueprint) SmallInteger(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for SmallInteger") + } + + 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_SmallInteger_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SmallInteger' +type Blueprint_SmallInteger_Call struct { + *mock.Call +} + +// SmallInteger is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) SmallInteger(column interface{}) *Blueprint_SmallInteger_Call { + return &Blueprint_SmallInteger_Call{Call: _e.mock.On("SmallInteger", column)} +} + +func (_c *Blueprint_SmallInteger_Call) Run(run func(column string)) *Blueprint_SmallInteger_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_SmallInteger_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_SmallInteger_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_SmallInteger_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_SmallInteger_Call { + _c.Call.Return(run) + return _c +} + // String provides a mock function with given fields: column, length func (_m *Blueprint) String(column string, length ...int) schema.ColumnDefinition { _va := make([]interface{}, len(length)) @@ -786,6 +1074,102 @@ func (_c *Blueprint_String_Call) RunAndReturn(run func(string, ...int) schema.Co return _c } +// TinyIncrements provides a mock function with given fields: column +func (_m *Blueprint) TinyIncrements(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TinyIncrements") + } + + 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_TinyIncrements_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TinyIncrements' +type Blueprint_TinyIncrements_Call struct { + *mock.Call +} + +// TinyIncrements is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) TinyIncrements(column interface{}) *Blueprint_TinyIncrements_Call { + return &Blueprint_TinyIncrements_Call{Call: _e.mock.On("TinyIncrements", column)} +} + +func (_c *Blueprint_TinyIncrements_Call) Run(run func(column string)) *Blueprint_TinyIncrements_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_TinyIncrements_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_TinyIncrements_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_TinyIncrements_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_TinyIncrements_Call { + _c.Call.Return(run) + return _c +} + +// TinyInteger provides a mock function with given fields: column +func (_m *Blueprint) TinyInteger(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TinyInteger") + } + + 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_TinyInteger_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TinyInteger' +type Blueprint_TinyInteger_Call struct { + *mock.Call +} + +// TinyInteger is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) TinyInteger(column interface{}) *Blueprint_TinyInteger_Call { + return &Blueprint_TinyInteger_Call{Call: _e.mock.On("TinyInteger", column)} +} + +func (_c *Blueprint_TinyInteger_Call) Run(run func(column string)) *Blueprint_TinyInteger_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_TinyInteger_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_TinyInteger_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_TinyInteger_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_TinyInteger_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) @@ -882,6 +1266,198 @@ func (_c *Blueprint_UnsignedBigInteger_Call) RunAndReturn(run func(string) schem return _c } +// UnsignedInteger provides a mock function with given fields: column +func (_m *Blueprint) UnsignedInteger(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for UnsignedInteger") + } + + 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_UnsignedInteger_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UnsignedInteger' +type Blueprint_UnsignedInteger_Call struct { + *mock.Call +} + +// UnsignedInteger is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) UnsignedInteger(column interface{}) *Blueprint_UnsignedInteger_Call { + return &Blueprint_UnsignedInteger_Call{Call: _e.mock.On("UnsignedInteger", column)} +} + +func (_c *Blueprint_UnsignedInteger_Call) Run(run func(column string)) *Blueprint_UnsignedInteger_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_UnsignedInteger_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_UnsignedInteger_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_UnsignedInteger_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_UnsignedInteger_Call { + _c.Call.Return(run) + return _c +} + +// UnsignedMediumInteger provides a mock function with given fields: column +func (_m *Blueprint) UnsignedMediumInteger(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for UnsignedMediumInteger") + } + + 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_UnsignedMediumInteger_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UnsignedMediumInteger' +type Blueprint_UnsignedMediumInteger_Call struct { + *mock.Call +} + +// UnsignedMediumInteger is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) UnsignedMediumInteger(column interface{}) *Blueprint_UnsignedMediumInteger_Call { + return &Blueprint_UnsignedMediumInteger_Call{Call: _e.mock.On("UnsignedMediumInteger", column)} +} + +func (_c *Blueprint_UnsignedMediumInteger_Call) Run(run func(column string)) *Blueprint_UnsignedMediumInteger_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_UnsignedMediumInteger_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_UnsignedMediumInteger_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_UnsignedMediumInteger_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_UnsignedMediumInteger_Call { + _c.Call.Return(run) + return _c +} + +// UnsignedSmallInteger provides a mock function with given fields: column +func (_m *Blueprint) UnsignedSmallInteger(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for UnsignedSmallInteger") + } + + 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_UnsignedSmallInteger_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UnsignedSmallInteger' +type Blueprint_UnsignedSmallInteger_Call struct { + *mock.Call +} + +// UnsignedSmallInteger is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) UnsignedSmallInteger(column interface{}) *Blueprint_UnsignedSmallInteger_Call { + return &Blueprint_UnsignedSmallInteger_Call{Call: _e.mock.On("UnsignedSmallInteger", column)} +} + +func (_c *Blueprint_UnsignedSmallInteger_Call) Run(run func(column string)) *Blueprint_UnsignedSmallInteger_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_UnsignedSmallInteger_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_UnsignedSmallInteger_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_UnsignedSmallInteger_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_UnsignedSmallInteger_Call { + _c.Call.Return(run) + return _c +} + +// UnsignedTinyInteger provides a mock function with given fields: column +func (_m *Blueprint) UnsignedTinyInteger(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for UnsignedTinyInteger") + } + + 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_UnsignedTinyInteger_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UnsignedTinyInteger' +type Blueprint_UnsignedTinyInteger_Call struct { + *mock.Call +} + +// UnsignedTinyInteger is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) UnsignedTinyInteger(column interface{}) *Blueprint_UnsignedTinyInteger_Call { + return &Blueprint_UnsignedTinyInteger_Call{Call: _e.mock.On("UnsignedTinyInteger", column)} +} + +func (_c *Blueprint_UnsignedTinyInteger_Call) Run(run func(column string)) *Blueprint_UnsignedTinyInteger_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_UnsignedTinyInteger_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_UnsignedTinyInteger_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_UnsignedTinyInteger_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_UnsignedTinyInteger_Call { + _c.Call.Return(run) + return _c +} + // NewBlueprint creates a new instance of Blueprint. 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 NewBlueprint(t interface { diff --git a/mocks/database/schema/ColumnDefinition.go b/mocks/database/schema/ColumnDefinition.go index 9fe90a154..c0070bb3c 100644 --- a/mocks/database/schema/ColumnDefinition.go +++ b/mocks/database/schema/ColumnDefinition.go @@ -294,6 +294,141 @@ func (_c *ColumnDefinition_GetNullable_Call) RunAndReturn(run func() bool) *Colu return _c } +// GetPlaces provides a mock function with given fields: +func (_m *ColumnDefinition) GetPlaces() int { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetPlaces") + } + + var r0 int + if rf, ok := ret.Get(0).(func() int); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(int) + } + + return r0 +} + +// ColumnDefinition_GetPlaces_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPlaces' +type ColumnDefinition_GetPlaces_Call struct { + *mock.Call +} + +// GetPlaces is a helper method to define mock.On call +func (_e *ColumnDefinition_Expecter) GetPlaces() *ColumnDefinition_GetPlaces_Call { + return &ColumnDefinition_GetPlaces_Call{Call: _e.mock.On("GetPlaces")} +} + +func (_c *ColumnDefinition_GetPlaces_Call) Run(run func()) *ColumnDefinition_GetPlaces_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ColumnDefinition_GetPlaces_Call) Return(_a0 int) *ColumnDefinition_GetPlaces_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ColumnDefinition_GetPlaces_Call) RunAndReturn(run func() int) *ColumnDefinition_GetPlaces_Call { + _c.Call.Return(run) + return _c +} + +// GetPrecision provides a mock function with given fields: +func (_m *ColumnDefinition) GetPrecision() int { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetPrecision") + } + + var r0 int + if rf, ok := ret.Get(0).(func() int); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(int) + } + + return r0 +} + +// ColumnDefinition_GetPrecision_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPrecision' +type ColumnDefinition_GetPrecision_Call struct { + *mock.Call +} + +// GetPrecision is a helper method to define mock.On call +func (_e *ColumnDefinition_Expecter) GetPrecision() *ColumnDefinition_GetPrecision_Call { + return &ColumnDefinition_GetPrecision_Call{Call: _e.mock.On("GetPrecision")} +} + +func (_c *ColumnDefinition_GetPrecision_Call) Run(run func()) *ColumnDefinition_GetPrecision_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ColumnDefinition_GetPrecision_Call) Return(_a0 int) *ColumnDefinition_GetPrecision_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ColumnDefinition_GetPrecision_Call) RunAndReturn(run func() int) *ColumnDefinition_GetPrecision_Call { + _c.Call.Return(run) + return _c +} + +// GetTotal provides a mock function with given fields: +func (_m *ColumnDefinition) GetTotal() int { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetTotal") + } + + var r0 int + if rf, ok := ret.Get(0).(func() int); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(int) + } + + return r0 +} + +// ColumnDefinition_GetTotal_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTotal' +type ColumnDefinition_GetTotal_Call struct { + *mock.Call +} + +// GetTotal is a helper method to define mock.On call +func (_e *ColumnDefinition_Expecter) GetTotal() *ColumnDefinition_GetTotal_Call { + return &ColumnDefinition_GetTotal_Call{Call: _e.mock.On("GetTotal")} +} + +func (_c *ColumnDefinition_GetTotal_Call) Run(run func()) *ColumnDefinition_GetTotal_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ColumnDefinition_GetTotal_Call) Return(_a0 int) *ColumnDefinition_GetTotal_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ColumnDefinition_GetTotal_Call) RunAndReturn(run func() int) *ColumnDefinition_GetTotal_Call { + _c.Call.Return(run) + return _c +} + // GetType provides a mock function with given fields: func (_m *ColumnDefinition) GetType() string { ret := _m.Called() diff --git a/mocks/database/schema/Grammar.go b/mocks/database/schema/Grammar.go index 0cc577b29..267c19044 100644 --- a/mocks/database/schema/Grammar.go +++ b/mocks/database/schema/Grammar.go @@ -761,6 +761,143 @@ func (_c *Grammar_TypeBigInteger_Call) RunAndReturn(run func(schema.ColumnDefini return _c } +// TypeDecimal provides a mock function with given fields: column +func (_m *Grammar) TypeDecimal(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeDecimal") + } + + 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_TypeDecimal_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeDecimal' +type Grammar_TypeDecimal_Call struct { + *mock.Call +} + +// TypeDecimal is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeDecimal(column interface{}) *Grammar_TypeDecimal_Call { + return &Grammar_TypeDecimal_Call{Call: _e.mock.On("TypeDecimal", column)} +} + +func (_c *Grammar_TypeDecimal_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeDecimal_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeDecimal_Call) Return(_a0 string) *Grammar_TypeDecimal_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeDecimal_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeDecimal_Call { + _c.Call.Return(run) + return _c +} + +// TypeDouble provides a mock function with given fields: +func (_m *Grammar) TypeDouble() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for TypeDouble") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeDouble_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeDouble' +type Grammar_TypeDouble_Call struct { + *mock.Call +} + +// TypeDouble is a helper method to define mock.On call +func (_e *Grammar_Expecter) TypeDouble() *Grammar_TypeDouble_Call { + return &Grammar_TypeDouble_Call{Call: _e.mock.On("TypeDouble")} +} + +func (_c *Grammar_TypeDouble_Call) Run(run func()) *Grammar_TypeDouble_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Grammar_TypeDouble_Call) Return(_a0 string) *Grammar_TypeDouble_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeDouble_Call) RunAndReturn(run func() string) *Grammar_TypeDouble_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) + + if len(ret) == 0 { + panic("no return value specified for TypeFloat") + } + + 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_TypeFloat_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeFloat' +type Grammar_TypeFloat_Call struct { + *mock.Call +} + +// TypeFloat is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeFloat(column interface{}) *Grammar_TypeFloat_Call { + return &Grammar_TypeFloat_Call{Call: _e.mock.On("TypeFloat", column)} +} + +func (_c *Grammar_TypeFloat_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeFloat_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeFloat_Call) Return(_a0 string) *Grammar_TypeFloat_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeFloat_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeFloat_Call { + _c.Call.Return(run) + return _c +} + // TypeInteger provides a mock function with given fields: column func (_m *Grammar) TypeInteger(column schema.ColumnDefinition) string { ret := _m.Called(column) @@ -807,6 +944,98 @@ func (_c *Grammar_TypeInteger_Call) RunAndReturn(run func(schema.ColumnDefinitio return _c } +// TypeMediumInteger provides a mock function with given fields: column +func (_m *Grammar) TypeMediumInteger(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeMediumInteger") + } + + 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_TypeMediumInteger_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeMediumInteger' +type Grammar_TypeMediumInteger_Call struct { + *mock.Call +} + +// TypeMediumInteger is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeMediumInteger(column interface{}) *Grammar_TypeMediumInteger_Call { + return &Grammar_TypeMediumInteger_Call{Call: _e.mock.On("TypeMediumInteger", column)} +} + +func (_c *Grammar_TypeMediumInteger_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeMediumInteger_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeMediumInteger_Call) Return(_a0 string) *Grammar_TypeMediumInteger_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeMediumInteger_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeMediumInteger_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) + + if len(ret) == 0 { + panic("no return value specified for TypeSmallInteger") + } + + 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_TypeSmallInteger_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeSmallInteger' +type Grammar_TypeSmallInteger_Call struct { + *mock.Call +} + +// TypeSmallInteger is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeSmallInteger(column interface{}) *Grammar_TypeSmallInteger_Call { + return &Grammar_TypeSmallInteger_Call{Call: _e.mock.On("TypeSmallInteger", column)} +} + +func (_c *Grammar_TypeSmallInteger_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeSmallInteger_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeSmallInteger_Call) Return(_a0 string) *Grammar_TypeSmallInteger_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeSmallInteger_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeSmallInteger_Call { + _c.Call.Return(run) + return _c +} + // TypeString provides a mock function with given fields: column func (_m *Grammar) TypeString(column schema.ColumnDefinition) string { ret := _m.Called(column) @@ -853,6 +1082,52 @@ func (_c *Grammar_TypeString_Call) RunAndReturn(run func(schema.ColumnDefinition return _c } +// TypeTinyInteger provides a mock function with given fields: column +func (_m *Grammar) TypeTinyInteger(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeTinyInteger") + } + + 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_TypeTinyInteger_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeTinyInteger' +type Grammar_TypeTinyInteger_Call struct { + *mock.Call +} + +// TypeTinyInteger is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeTinyInteger(column interface{}) *Grammar_TypeTinyInteger_Call { + return &Grammar_TypeTinyInteger_Call{Call: _e.mock.On("TypeTinyInteger", column)} +} + +func (_c *Grammar_TypeTinyInteger_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeTinyInteger_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeTinyInteger_Call) Return(_a0 string) *Grammar_TypeTinyInteger_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeTinyInteger_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeTinyInteger_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 {