From 460386169110f3419a42525237fa36784cc14097 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Wed, 21 Jul 2021 16:55:33 +0700 Subject: [PATCH] feat: float and real type --- create.go | 20 ++++++++++++++++++++ create_test.go | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) 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) }