Skip to content

Commit

Permalink
feat: CreateTableQuery.PartitionBy and CreateTableQuery.TableSpace
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Nov 21, 2021
1 parent 687a004 commit cd3ab4d
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/dbtest/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,12 @@ func TestQuery(t *testing.T) {
ColumnExpr(`email VARCHAR`).
ColumnExpr(`password VARCHAR`)
},
func(db *bun.DB) schema.QueryAppender {
return db.NewCreateTable().Model(new(Model)).PartitionBy("HASH (id)")
},
func(db *bun.DB) schema.QueryAppender {
return db.NewCreateTable().Model(new(Model)).TableSpace("fasttablespace")
},
}

timeRE := regexp.MustCompile(`'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+(\+\d{2}:\d{2})?'`)
Expand Down
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-102
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `str` VARCHAR(255), PRIMARY KEY (`id`)) PARTITION BY HASH (id)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-103
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `str` VARCHAR(255), PRIMARY KEY (`id`)) TABLESPACE `fasttablespace`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-102
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `str` VARCHAR(255), PRIMARY KEY (`id`)) PARTITION BY HASH (id)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-103
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `str` VARCHAR(255), PRIMARY KEY (`id`)) TABLESPACE `fasttablespace`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-102
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "models" ("id" BIGSERIAL NOT NULL, "str" VARCHAR, PRIMARY KEY ("id")) PARTITION BY HASH (id)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-103
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "models" ("id" BIGSERIAL NOT NULL, "str" VARCHAR, PRIMARY KEY ("id")) TABLESPACE "fasttablespace"
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-102
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "models" ("id" BIGSERIAL NOT NULL, "str" VARCHAR, PRIMARY KEY ("id")) PARTITION BY HASH (id)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-103
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "models" ("id" BIGSERIAL NOT NULL, "str" VARCHAR, PRIMARY KEY ("id")) TABLESPACE "fasttablespace"
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-102
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "models" ("id" INTEGER NOT NULL, "str" VARCHAR, PRIMARY KEY ("id")) PARTITION BY HASH (id)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-103
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "models" ("id" INTEGER NOT NULL, "str" VARCHAR, PRIMARY KEY ("id")) TABLESPACE "fasttablespace"
12 changes: 12 additions & 0 deletions query_table_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ func (q *CreateTableQuery) ForeignKey(query string, args ...interface{}) *Create
return q
}

func (q *CreateTableQuery) PartitionBy(query string, args ...interface{}) *CreateTableQuery {
q.partitionBy = schema.SafeQuery(query, args)
return q
}

func (q *CreateTableQuery) TableSpace(tablespace string) *CreateTableQuery {
q.tablespace = schema.UnsafeIdent(tablespace)
return q
}

//------------------------------------------------------------------------------

func (q *CreateTableQuery) Operation() string {
return "CREATE TABLE"
}
Expand Down

0 comments on commit cd3ab4d

Please sign in to comment.