WIP: Insert sets PK
WIP: Insert sets PK
This commit is contained in:
+51
-2
@@ -15,45 +15,94 @@ type Test struct {
|
||||
StringField string `sql:"nn"`
|
||||
}
|
||||
|
||||
func (t Test) IsInsertable() bool {
|
||||
func (t *Test) IsInsertable() bool {
|
||||
return t.ID == 0
|
||||
}
|
||||
|
||||
func (t *Test) SetPk(pks ...any) {
|
||||
t.ID = pks[0].(int)
|
||||
}
|
||||
|
||||
type TestWithFk struct {
|
||||
ID int `sql:"pk"`
|
||||
TestID int `sql:"nn;fk=Test.ID"`
|
||||
}
|
||||
|
||||
func (t *TestWithFk) IsInsertable() bool {
|
||||
return t.ID == 0
|
||||
}
|
||||
|
||||
func (t *TestWithFk) SetPk(pks ...any) {
|
||||
t.ID = pks[0].(int)
|
||||
}
|
||||
|
||||
type TestWithFkAndFkId struct {
|
||||
ID int `sql:"pk"`
|
||||
TestID int `sql:"nn;fk=Test.ID;fk_id=custom_fk"`
|
||||
}
|
||||
|
||||
func (t *TestWithFkAndFkId) IsInsertable() bool {
|
||||
return t.ID == 0
|
||||
}
|
||||
|
||||
func (t *TestWithFkAndFkId) SetPk(pks ...any) {
|
||||
t.ID = pks[0].(int)
|
||||
}
|
||||
|
||||
type TestWithCompositePk struct {
|
||||
ID int `sql:"nn;pk;"`
|
||||
Name string `sql:"nn;pk"`
|
||||
}
|
||||
|
||||
func (t TestWithCompositePk) IsInsertable() bool {
|
||||
func (t *TestWithCompositePk) IsInsertable() bool {
|
||||
return t.ID == 0 && t.Name == ""
|
||||
}
|
||||
|
||||
func (t *TestWithCompositePk) SetPk(pks ...any) {
|
||||
t.ID = pks[0].(int)
|
||||
t.Name = pks[1].(string)
|
||||
}
|
||||
|
||||
type TestWithCompositeFk struct {
|
||||
ID int `sql:"nn;pk"`
|
||||
CompositeFkId int `sql:"nn;fk=TestWithCompositePk.ID;"`
|
||||
CompositeFkName string `sql:"nn;fk=TestWithCompositePk.Name;"`
|
||||
}
|
||||
|
||||
func (t *TestWithCompositeFk) IsInsertable() bool {
|
||||
return t.ID == 0
|
||||
}
|
||||
|
||||
func (t *TestWithCompositeFk) SetPk(pks ...any) {
|
||||
t.ID = pks[0].(int)
|
||||
}
|
||||
|
||||
type TestWithBool struct {
|
||||
ID int `sql:"pk"`
|
||||
BoolField bool `sql:"nn"`
|
||||
}
|
||||
|
||||
func (t *TestWithBool) IsInsertable() bool {
|
||||
return t.ID == 0
|
||||
}
|
||||
|
||||
func (t *TestWithBool) SetPk(pks ...any) {
|
||||
t.ID = pks[0].(int)
|
||||
}
|
||||
|
||||
type TestWithTime struct {
|
||||
ID int `sql:"pk"`
|
||||
TimeField int64 `sql:"nn"`
|
||||
}
|
||||
|
||||
func (t *TestWithTime) IsInsertable() bool {
|
||||
return t.ID == 0
|
||||
}
|
||||
|
||||
func (t *TestWithTime) SetPk(pks ...any) {
|
||||
t.ID = pks[0].(int)
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
log.SetupLogs("Info")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user