Skip to content
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
6 changes: 6 additions & 0 deletions orm/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ var (
nullBoolType = reflect.TypeOf((*sql.NullBool)(nil)).Elem()
nullFloatType = reflect.TypeOf((*sql.NullFloat64)(nil)).Elem()
nullIntType = reflect.TypeOf((*sql.NullInt64)(nil)).Elem()
nullInt32Type = reflect.TypeOf((*sql.NullInt32)(nil)).Elem()
nullInt16Type = reflect.TypeOf((*sql.NullInt16)(nil)).Elem()
nullStringType = reflect.TypeOf((*sql.NullString)(nil)).Elem()
jsonRawMessageType = reflect.TypeOf((*json.RawMessage)(nil)).Elem()
)
Expand Down Expand Up @@ -1243,6 +1245,10 @@ func sqlType(typ reflect.Type) string {
return pgTypeDoublePrecision
case nullIntType:
return pgTypeBigint
case nullInt32Type:
return pgTypeInteger
case nullInt16Type:
return pgTypeSmallint
case nullStringType:
return pgTypeText
case jsonRawMessageType:
Expand Down
4 changes: 3 additions & 1 deletion orm/table_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type CreateTableModel struct {
NullBool sql.NullBool
NullFloat64 sql.NullFloat64
NullInt64 sql.NullInt64
NullInt32 sql.NullInt32
NullInt16 sql.NullInt16
NullString sql.NullString
Slice []int
SliceArray []int `pg:",array"`
Expand Down Expand Up @@ -96,7 +98,7 @@ var _ = Describe("CreateTable", func() {
q := NewQuery(nil, &CreateTableModel{})

s := createTableQueryString(q, nil)
Expect(s).To(Equal(`CREATE TABLE "create_table_models" ("id" bigserial, "serial" bigint, "int8" smallint, "uint8" smallint, "int16" smallint, "uint16" integer, "int32" integer, "uint32" bigint, "int64" bigint, "uint64" bigint, "float32" real, "float64" double precision, "decimal" decimal(10,10), "byte_slice" bytea, "byte_array" bytea, "string" text DEFAULT 'D''Angelo', "varchar" varchar(500), "time" timestamptz DEFAULT now(), "duration" bigint, "not_null" bigint NOT NULL, "null_bool" boolean, "null_float64" double precision, "null_int64" bigint, "null_string" text, "slice" jsonb, "slice_array" bigint[], "map" jsonb, "map_hstore" hstore, "struct" jsonb, "struct_ptr" jsonb, "unique" bigint UNIQUE, "unique_field1" bigint, "unique_field2" bigint, "json_raw_message" jsonb, PRIMARY KEY ("id"), UNIQUE ("unique"), UNIQUE ("unique_field1", "unique_field2"))`))
Expect(s).To(Equal(`CREATE TABLE "create_table_models" ("id" bigserial, "serial" bigint, "int8" smallint, "uint8" smallint, "int16" smallint, "uint16" integer, "int32" integer, "uint32" bigint, "int64" bigint, "uint64" bigint, "float32" real, "float64" double precision, "decimal" decimal(10,10), "byte_slice" bytea, "byte_array" bytea, "string" text DEFAULT 'D''Angelo', "varchar" varchar(500), "time" timestamptz DEFAULT now(), "duration" bigint, "not_null" bigint NOT NULL, "null_bool" boolean, "null_float64" double precision, "null_int64" bigint, "null_int32" integer, "null_int16" smallint, "null_string" text, "slice" jsonb, "slice_array" bigint[], "map" jsonb, "map_hstore" hstore, "struct" jsonb, "struct_ptr" jsonb, "unique" bigint UNIQUE, "unique_field1" bigint, "unique_field2" bigint, "json_raw_message" jsonb, PRIMARY KEY ("id"), UNIQUE ("unique"), UNIQUE ("unique_field1", "unique_field2"))`))
})

It("creates new table without primary key", func() {
Expand Down