-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_entity.go
49 lines (39 loc) · 1.09 KB
/
test_entity.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"context"
"time"
)
//go:generate go run github.com/solta-dev/gentity
type SomeInts int
const (
Int1 SomeInts = iota
Int2 SomeInts = iota
Int3 SomeInts = iota
)
// gentity
type Test struct {
ID uint64 `gentity:"unique=primary autoincrement"`
IntA int `gentity:"index=test_int_a_int_b"`
IntB SomeInts `gentity:"index=test_int_a_int_b"`
StrA string `gentity:"unique=test_str_a"`
TimeA time.Time `gentity:""`
}
func (Test) createTable(ctx context.Context) error {
pgConn := ctx.Value(DBExecutorKey("dbExecutor")).(DBExecutor)
if _, err := pgConn.Exec(context.Background(), `CREATE TABLE tests (
id bigserial PRIMARY KEY,
int_a integer NOT NULL,
int_b integer NOT NULL,
str_a varchar(256) NOT NULL,
time_a timestamp NOT NULL DEFAULT now()
)`); err != nil {
return err
}
if _, err := pgConn.Exec(context.Background(), `CREATE INDEX test_int_a_int_b ON tests (int_a, int_b)`); err != nil {
return err
}
if _, err := pgConn.Exec(context.Background(), `CREATE UNIQUE INDEX test_str_a ON tests (str_a)`); err != nil {
return err
}
return nil
}