feat: float and real type

This commit is contained in:
Reinaldy Rafli 2021-07-21 16:55:33 +07:00
parent 9c7a6285ca
commit 4603861691
2 changed files with 23 additions and 1 deletions

View File

@ -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,

View File

@ -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)
}