Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow bigint columns in sqlite #143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions translators/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (p *SQLite) CreateTable(t fizz.Table) (string, error) {
for _, c := range t.Columns {
if c.Primary {
switch strings.ToLower(c.ColType) {
case "integer", "int":
case "integer", "int", "bigint":
s = fmt.Sprintf("\"%s\" INTEGER PRIMARY KEY AUTOINCREMENT", c.Name)
case "string", "text", "uuid":
s = fmt.Sprintf("\"%s\" TEXT PRIMARY KEY", c.Name)
Expand Down Expand Up @@ -400,7 +400,7 @@ func (p *SQLite) colType(c fizz.Column) string {
return "NUMERIC"
case "string", "text":
return "TEXT"
case "int", "integer":
case "int", "integer", "bigint":
return "INTEGER"
case "float":
// precision and scale not supported here
Expand Down
47 changes: 47 additions & 0 deletions translators/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,42 @@ PRIMARY KEY("user_id", "profile_id")
r.Equal(ddl, res)
}

func (p *SQLiteSuite) Test_SQLite_CreateTable_WithBigIntPrimaryKey() {
r := p.Require()
ddl := `CREATE TABLE "users" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"first_name" TEXT NOT NULL,
"last_name" TEXT NOT NULL,
"email" TEXT NOT NULL,
"permissions" TEXT,
"age" INTEGER DEFAULT '40',
"raw" BLOB NOT NULL,
"into" INTEGER NOT NULL,
"flotante" REAL NOT NULL,
"json" TEXT NOT NULL,
"bytes" BLOB NOT NULL,
"created_at" DATETIME NOT NULL,
"updated_at" DATETIME NOT NULL
);`

res, _ := fizz.AString(`
create_table("users") {
t.Column("id", "bigint", {"primary": true})
t.Column("first_name", "string", {})
t.Column("last_name", "string", {})
t.Column("email", "string", {"size":20})
t.Column("permissions", "text", {"null": true})
t.Column("age", "integer", {"null": true, "default": 40})
t.Column("raw", "blob", {})
t.Column("into", "int", {})
t.Column("flotante", "float", {})
t.Column("json", "json", {})
t.Column("bytes", "[]byte", {})
}
`, sqt)
r.Equal(ddl, res)
}

func (p *SQLiteSuite) Test_SQLite_DropTable() {
r := p.Require()

Expand Down Expand Up @@ -208,6 +244,17 @@ func (p *SQLiteSuite) Test_SQLite_AddColumn() {
r.Equal(ddl, res)
}

func (p *SQLiteSuite) Test_SQLite_AddBigIntColumn() {
r := p.Require()

ddl := `ALTER TABLE "users" ADD COLUMN "mycolumn" INTEGER NOT NULL;`
schema.schema["users"] = &fizz.Table{}

res, _ := fizz.AString(`add_column("users", "mycolumn", "bigint")`, sqt)

r.Equal(ddl, res)
}

func (p *SQLiteSuite) Test_SQLite_DropColumn() {
r := p.Require()
ddl := `CREATE TABLE "_users_tmp" (
Expand Down