diff --git a/create.go b/create.go index aafe4ee..1748e03 100644 --- a/create.go +++ b/create.go @@ -99,6 +99,26 @@ func (b CreateBuilder) IntColumn(name string, extras ...string) CreateBuilder { }).(CreateBuilder) } +// RealColumn only available for MSSQL, PostgreSQL, and SQLite. +// For MySQL, please refer to FloatColumn, or create your own with AddColumn() with Type: "DOUBLE". +func (b CreateBuilder) RealColumn(name string, extras ...string) CreateBuilder { + return builder.Append(b, "Columns", ColumnDef{ + Name: name, + Type: "REAL", + Extras: extras, + }).(CreateBuilder) +} + +// FloatColumn only available for MySQL and MSSQL. +// For PostgreSQL and SQLite, please refer to RealColumn. +func (b CreateBuilder) FloatColumn(name string, extras ...string) CreateBuilder { + return builder.Append(b, "Columns", ColumnDef{ + Name: name, + Type: "FLOAT", + Extras: extras, + }).(CreateBuilder) +} + func (b CreateBuilder) DateTimeColumn(name string, extras ...string) CreateBuilder { return builder.Append(b, "Columns", ColumnDef{ Name: name, diff --git a/create_test.go b/create_test.go index 6049547..b62e50e 100644 --- a/create_test.go +++ b/create_test.go @@ -24,12 +24,14 @@ func TestCreate(t *testing.T) { JSONColumn("json"). JSONBColumn("jsonb"). BlobColumn("blob"). + RealColumn("real"). + FloatColumn("float"). AddColumn(bob.ColumnDef{Name: "custom", Type: "custom"}). ToSql() if err != nil { t.Fatal(err.Error()) } - result := "CREATE TABLE \"users\" (\"uuid\" UUID, \"string\" VARCHAR(255), \"text\" TEXT, \"date\" DATE, \"boolean\" BOOLEAN, \"integer\" INTEGER, \"int\" INT, \"timestamp\" TIMESTAMP, \"time\" TIME, \"date\" DATE, \"datetime\" DATETIME, \"json\" JSON, \"jsonb\" JSONB, \"blob\" BLOB, \"custom\" custom);" + result := "CREATE TABLE \"users\" (\"uuid\" UUID, \"string\" VARCHAR(255), \"text\" TEXT, \"date\" DATE, \"boolean\" BOOLEAN, \"integer\" INTEGER, \"int\" INT, \"timestamp\" TIMESTAMP, \"time\" TIME, \"date\" DATE, \"datetime\" DATETIME, \"json\" JSON, \"jsonb\" JSONB, \"blob\" BLOB, \"real\" REAL, \"float\" FLOAT, \"custom\" custom);" if sql != result { t.Fatal("sql is not equal to result:", sql) }