Skip to content

Commit c9dc404

Browse files
committed
feat(schema): expand Table and Fields also add ForeignKey
Refs: #7
1 parent 103f6cf commit c9dc404

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

internal/schema/schema.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
package schema
22

3+
type ReferenceOption string
4+
5+
const (
6+
ReferenceOptionCascade ReferenceOption = "CASCADE"
7+
ReferenceOptionNoAction ReferenceOption = "NO ACTION"
8+
ReferenceOptionSetDefault ReferenceOption = "SET DEFAULT"
9+
ReferenceOptionSetNull ReferenceOption = "SET NULL"
10+
ReferenceOptionRestrict ReferenceOption = "RESTRICT"
11+
)
12+
313
type Table struct {
4-
Name string
5-
Schema string
6-
Fields []*Field
14+
Fields []*Field
15+
ForeingKeys []*ForeingKey
16+
Name string
17+
Schema string
718
}
819

920
type Field struct {
10-
Name string
11-
Type string
21+
Default string
22+
Name string
23+
Nullable bool
24+
Primary bool
25+
Type string
26+
}
27+
28+
type ForeingKey struct {
29+
Fields []*Field
30+
Name string
31+
OnDelete ReferenceOption
32+
OnUpdate ReferenceOption
33+
ReferredTable []*Table
34+
ReferredFields []*Field
1235
}

internal/sqlok_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type User struct {
1616
func TestHttpTransport(t *testing.T) {
1717
user := User{}
1818
userType := reflect.TypeOf(user)
19-
for i := 0; i < userType.NumField(); i++ {
19+
for i := range userType.NumField() {
2020
field := userType.Field(i)
2121
tag := field.Tag.Get("sqlok")
2222

0 commit comments

Comments
 (0)