Skip to content

Commit

Permalink
feat: float and real type
Browse files Browse the repository at this point in the history
  • Loading branch information
aldy505 committed Jul 21, 2021
1 parent 9c7a628 commit 4603861
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 4603861

Please sign in to comment.