WIP: Insert sets PK

This commit is contained in:
2026-05-23 20:19:25 +02:00
parent 890151b490
commit 5d892a15ef
6 changed files with 59 additions and 54 deletions
+2 -27
View File
@@ -15,14 +15,10 @@ 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"`
@@ -32,10 +28,6 @@ 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"`
@@ -54,15 +46,10 @@ type TestWithCompositePk struct {
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;"`
@@ -73,10 +60,6 @@ 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"`
@@ -86,10 +69,6 @@ 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"`
@@ -99,10 +78,6 @@ 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")