From e7c5add26801238b02dcf51525797d1b9149dbf8 Mon Sep 17 00:00:00 2001 From: liangfujian <50279811+liangfujian@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:46:16 +0800 Subject: [PATCH 01/10] =?UTF-8?q?postgresql=E5=85=B3=E9=94=AE=E5=AD=97?= =?UTF-8?q?=E5=85=85=E5=BD=93=E5=AD=97=E6=AE=B5=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/integration/client_test.go | 4 ++-- internal/integration/mysql.hcl | 4 ++++ internal/integration/postgresql.hcl | 4 ++++ internal/integration/sqlite.hcl | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/integration/client_test.go b/internal/integration/client_test.go index e340f524..bc1fc41d 100644 --- a/internal/integration/client_test.go +++ b/internal/integration/client_test.go @@ -494,11 +494,11 @@ func TestChangeJSON(t *testing.T) { } func TestModelJSON(t *testing.T) { - tag, err := c.QueryTag().Create(c.ChangeTag().SetName("test")) + tag, err := c.QueryTag().Create(c.ChangeTag().SetName("test").SetRight(true)) require.NoError(t, err) b, err := json.Marshal(tag) require.NoError(t, err) - require.Equal(t, fmt.Sprintf(`{"id":%d,"name":"test"}`, tag.ID), string(b)) + require.Equal(t, fmt.Sprintf(`{"id":%d,"name":"test","right":true}`, tag.ID), string(b)) } func TestModelStringer(t *testing.T) { diff --git a/internal/integration/mysql.hcl b/internal/integration/mysql.hcl index fbe07a64..c0d1c3db 100644 --- a/internal/integration/mysql.hcl +++ b/internal/integration/mysql.hcl @@ -109,6 +109,10 @@ database "db" { type = string } + column "right" { + type = boolean + } + index { columns = ["name"] unique = true diff --git a/internal/integration/postgresql.hcl b/internal/integration/postgresql.hcl index 17ea6a7e..07526b78 100644 --- a/internal/integration/postgresql.hcl +++ b/internal/integration/postgresql.hcl @@ -109,6 +109,10 @@ database "db" { type = string } + column "right" { + type = boolean + } + index { columns = ["name",] unique = true diff --git a/internal/integration/sqlite.hcl b/internal/integration/sqlite.hcl index 0a266f2d..61ce3489 100644 --- a/internal/integration/sqlite.hcl +++ b/internal/integration/sqlite.hcl @@ -109,6 +109,10 @@ database "db" { type = string } + column "right" { + type = boolean + } + index { columns = ["name"] unique = true From 508228b47c12f86414f81dd1aa0283b2f79d06c5 Mon Sep 17 00:00:00 2001 From: liangfujian <50279811+liangfujian@users.noreply.github.com> Date: Mon, 23 Oct 2023 17:22:56 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dpg=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=AD=97=E5=AF=BC=E8=87=B4=E7=9A=84=E8=AF=AD?= =?UTF-8?q?=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generator/client/golang/templates/queryx/insert.gotmpl | 2 +- generator/client/golang/templates/queryx/insert_test.gotmpl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generator/client/golang/templates/queryx/insert.gotmpl b/generator/client/golang/templates/queryx/insert.gotmpl index 4b0244fd..1a552424 100644 --- a/generator/client/golang/templates/queryx/insert.gotmpl +++ b/generator/client/golang/templates/queryx/insert.gotmpl @@ -55,7 +55,7 @@ func (s *InsertStatement) ToSQL() (string, []interface{}) { {{- if eq $.client.Adapter "mysql" }} sql = fmt.Sprintf("%s(`%s`)", sql, strings.Join(s.columns, "`, `")) {{- else }} - sql = fmt.Sprintf("%s(%s)", sql, strings.Join(s.columns, ", ")) + sql = fmt.Sprintf("%s(\"%s\")", sql, strings.Join(s.columns, "\", \"")) {{- end }} } else { {{- if eq $.client.Adapter "mysql" }} diff --git a/generator/client/golang/templates/queryx/insert_test.gotmpl b/generator/client/golang/templates/queryx/insert_test.gotmpl index 3815cc71..c1e49b1a 100644 --- a/generator/client/golang/templates/queryx/insert_test.gotmpl +++ b/generator/client/golang/templates/queryx/insert_test.gotmpl @@ -48,14 +48,14 @@ func TestNewInsert(t *testing.T) { s3 := NewInsert().Into("users").Columns("name", "email").Values("test", "test@example.com") sql, args = s3.ToSQL() - require.Equal(t, "INSERT INTO users(name, email) VALUES (?, ?)", sql) + require.Equal(t, "INSERT INTO users(\"name\", \"email\") VALUES (?, ?)", sql) require.Equal(t, []interface{}{"test", "test@example.com"}, args) s4 := NewInsert().Into("users").Columns("name", "email"). Values("test1", "test1@example.com"). Values("test2", "test2@example.com") sql, args = s4.ToSQL() - require.Equal(t, "INSERT INTO users(name, email) VALUES (?, ?), (?, ?)", sql) + require.Equal(t, "INSERT INTO users(\"name\", \"email\") VALUES (?, ?), (?, ?)", sql) require.Equal(t, []interface{}{"test1", "test1@example.com", "test2", "test2@example.com"}, args) } {{- end }} From c7aceba77361c6d64b2125d5573d28e28034d7ba Mon Sep 17 00:00:00 2001 From: liangfujian <50279811+liangfujian@users.noreply.github.com> Date: Mon, 23 Oct 2023 17:38:21 +0800 Subject: [PATCH 03/10] =?UTF-8?q?go=E6=B7=BB=E5=8A=A0update=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/integration/client_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/integration/client_test.go b/internal/integration/client_test.go index bc1fc41d..6e61338b 100644 --- a/internal/integration/client_test.go +++ b/internal/integration/client_test.go @@ -75,6 +75,16 @@ func TestCreate(t *testing.T) { } func TestInsertAll(t *testing.T) { + tag, err := c.QueryTag().Create(c.ChangeTag().SetRight(true).SetName("name")) + require.NoError(t, err) + + all, err := c.QueryTag().Where(c.TagID.EQ(tag.ID)).UpdateAll(c.ChangeTag().SetRight(false).SetName("name1")) + require.NoError(t, err) + require.True(t, all > 0) + require.Equal(t, true, tag.Right.Val) +} + +func TestUpdateAll(t *testing.T) { _, err := c.QueryUserPost().DeleteAll() require.NoError(t, err) From 3c9f4da3bc0e175fa1d907d86ce223e802aea1e6 Mon Sep 17 00:00:00 2001 From: liangfujian <50279811+liangfujian@users.noreply.github.com> Date: Tue, 24 Oct 2023 10:06:11 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dupdate=E8=AF=AD?= =?UTF-8?q?=E5=8F=A5=E4=BD=BF=E7=94=A8=E5=85=B3=E9=94=AE=E5=AD=97=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{select_test.go => select_test.gotmpl} | 6 ++++- .../templates/queryx/update.go_test.gotmpl | 22 +++++++++++++++++++ .../queryx/{update.go => update.gotmpl} | 6 ++++- .../golang/templates/queryx/update_test.go | 14 ------------ internal/integration/client_test.go | 5 ++++- 5 files changed, 36 insertions(+), 17 deletions(-) rename generator/client/golang/templates/queryx/{select_test.go => select_test.gotmpl} (84%) create mode 100644 generator/client/golang/templates/queryx/update.go_test.gotmpl rename generator/client/golang/templates/queryx/{update.go => update.gotmpl} (88%) delete mode 100644 generator/client/golang/templates/queryx/update_test.go diff --git a/generator/client/golang/templates/queryx/select_test.go b/generator/client/golang/templates/queryx/select_test.gotmpl similarity index 84% rename from generator/client/golang/templates/queryx/select_test.go rename to generator/client/golang/templates/queryx/select_test.gotmpl index 5c4b8977..eb82ebae 100644 --- a/generator/client/golang/templates/queryx/select_test.go +++ b/generator/client/golang/templates/queryx/select_test.gotmpl @@ -13,7 +13,11 @@ func TestSelect(t *testing.T) { require.Equal(t, []interface{}{}, args) sql, args = s.Update().Columns("name", "email").Values("test", "test@example.com").ToSQL() - require.Equal(t, `UPDATE users SET name = ?, email = ?`, sql) + {{- if eq .client.Adapter "mysql" }} + require.Equal(t, "UPDATE users SET `name` = ?, `email` = ?", sql) + {{- else }} + require.Equal(t, `UPDATE users SET "name" = ?, "email" = ?`, sql) + {{- end }} require.Equal(t, []interface{}{"test", "test@example.com"}, args) s1 := s.Limit(1) diff --git a/generator/client/golang/templates/queryx/update.go_test.gotmpl b/generator/client/golang/templates/queryx/update.go_test.gotmpl new file mode 100644 index 00000000..660a7eb8 --- /dev/null +++ b/generator/client/golang/templates/queryx/update.go_test.gotmpl @@ -0,0 +1,22 @@ +package queryx + +import ( + "testing" + + "github.com/stretchr/testify/require" +) +{{- if eq .client.Adapter "mysql" }} +func TestNewUpdate(t *testing.T) { + s := NewUpdate().Table("users").Columns("name", "email").Values("test", "test@example.com") + sql, args := s.ToSQL() + require.Equal(t, "UPDATE users SET `name` = ?, `email` = ?", sql) + require.Equal(t, []interface{}{"test", "test@example.com"}, args) +} +{{- else }} +func TestNewUpdate(t *testing.T) { + s := NewUpdate().Table("users").Columns("name", "email").Values("test", "test@example.com") + sql, args := s.ToSQL() + require.Equal(t, `UPDATE users SET "name" = ?, "email" = ?`, sql) + require.Equal(t, []interface{}{"test", "test@example.com"}, args) +} +{{- end }} \ No newline at end of file diff --git a/generator/client/golang/templates/queryx/update.go b/generator/client/golang/templates/queryx/update.gotmpl similarity index 88% rename from generator/client/golang/templates/queryx/update.go rename to generator/client/golang/templates/queryx/update.gotmpl index 2388cfbe..a31f8f31 100644 --- a/generator/client/golang/templates/queryx/update.go +++ b/generator/client/golang/templates/queryx/update.gotmpl @@ -49,7 +49,11 @@ func (s *UpdateStatement) ToSQL() (string, []interface{}) { sets := []string{} for _, col := range s.columns { - sets = append(sets, fmt.Sprintf("%s = ?", col)) + {{- if eq .client.Adapter "mysql" }} + sets = append(sets, fmt.Sprintf("`%s` = ?", col)) + {{- else }} + sets = append(sets, fmt.Sprintf("\"%s\" = ?", col)) + {{- end }} } sql = fmt.Sprintf("%s %s", sql, strings.Join(sets, ", ")) diff --git a/generator/client/golang/templates/queryx/update_test.go b/generator/client/golang/templates/queryx/update_test.go deleted file mode 100644 index 0d5e40e6..00000000 --- a/generator/client/golang/templates/queryx/update_test.go +++ /dev/null @@ -1,14 +0,0 @@ -package queryx - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func TestNewUpdate(t *testing.T) { - s := NewUpdate().Table("users").Columns("name", "email").Values("test", "test@example.com") - sql, args := s.ToSQL() - require.Equal(t, "UPDATE users SET name = ?, email = ?", sql) - require.Equal(t, []interface{}{"test", "test@example.com"}, args) -} diff --git a/internal/integration/client_test.go b/internal/integration/client_test.go index 6e61338b..76ae7174 100644 --- a/internal/integration/client_test.go +++ b/internal/integration/client_test.go @@ -75,10 +75,13 @@ func TestCreate(t *testing.T) { } func TestInsertAll(t *testing.T) { + _, err := c.QueryTag().DeleteAll() + require.NoError(t, err) + tag, err := c.QueryTag().Create(c.ChangeTag().SetRight(true).SetName("name")) require.NoError(t, err) - all, err := c.QueryTag().Where(c.TagID.EQ(tag.ID)).UpdateAll(c.ChangeTag().SetRight(false).SetName("name1")) + all, err := c.QueryTag().Where(c.TagID.EQ(tag.ID)).Where(c.TagRight.EQ(true)).UpdateAll(c.ChangeTag().SetRight(false).SetName("name1")) require.NoError(t, err) require.True(t, all > 0) require.Equal(t, true, tag.Right.Val) From a770bb6661fcced8817865f5d9ce0ebaa2181f4f Mon Sep 17 00:00:00 2001 From: liangfujian <50279811+liangfujian@users.noreply.github.com> Date: Tue, 24 Oct 2023 10:07:44 +0800 Subject: [PATCH 05/10] fmt tmpl --- generator/client/golang/templates/queryx/update.go_test.gotmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/client/golang/templates/queryx/update.go_test.gotmpl b/generator/client/golang/templates/queryx/update.go_test.gotmpl index 660a7eb8..44603e4c 100644 --- a/generator/client/golang/templates/queryx/update.go_test.gotmpl +++ b/generator/client/golang/templates/queryx/update.go_test.gotmpl @@ -19,4 +19,4 @@ func TestNewUpdate(t *testing.T) { require.Equal(t, `UPDATE users SET "name" = ?, "email" = ?`, sql) require.Equal(t, []interface{}{"test", "test@example.com"}, args) } -{{- end }} \ No newline at end of file +{{- end }} From 59fc258539f1d5fb91f19bedb40d6bc4e52af4fc Mon Sep 17 00:00:00 2001 From: liangfujian <50279811+liangfujian@users.noreply.github.com> Date: Tue, 24 Oct 2023 16:18:52 +0800 Subject: [PATCH 06/10] =?UTF-8?q?ts=E6=94=AF=E6=8C=81=E7=94=A8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E5=85=B3=E9=94=AE=E5=AD=97=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=A1=A8=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../typescript/templates/queryx/insert.tstmpl | 2 +- .../templates/queryx/{update.ts => update.tstmpl} | 6 +++++- internal/integration/client.test.ts | 13 +++++++++++-- internal/integration/client_test.go | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) rename generator/client/typescript/templates/queryx/{update.ts => update.tstmpl} (89%) diff --git a/generator/client/typescript/templates/queryx/insert.tstmpl b/generator/client/typescript/templates/queryx/insert.tstmpl index 0f0ca8fe..481f20fe 100644 --- a/generator/client/typescript/templates/queryx/insert.tstmpl +++ b/generator/client/typescript/templates/queryx/insert.tstmpl @@ -55,7 +55,7 @@ export class InsertStatement { {{- if eq $.client.Adapter "mysql" }} sql = `${sql} (\`${this._columns.join("`, `")}\`)`; {{- else }} - sql = `${sql} (${this._columns.join(", ")})`; + sql = `${sql} (\"${this._columns.join("\", \"")}\")`; {{- end }} } else { {{- if eq $.client.Adapter "mysql" }} diff --git a/generator/client/typescript/templates/queryx/update.ts b/generator/client/typescript/templates/queryx/update.tstmpl similarity index 89% rename from generator/client/typescript/templates/queryx/update.ts rename to generator/client/typescript/templates/queryx/update.tstmpl index 5a85e332..7ba385c4 100644 --- a/generator/client/typescript/templates/queryx/update.ts +++ b/generator/client/typescript/templates/queryx/update.tstmpl @@ -48,7 +48,11 @@ export class UpdateStatement { let sets = []; if (this._columns !== undefined) { for (let col of this._columns) { - sets.push(`${col} = ?`); + {{- if eq $.client.Adapter "mysql" }} + sets.push(`\`${col}\` = ?`); + {{- else }} + sets.push(`\"${col}\" = ?`); + {{- end }} } } diff --git a/internal/integration/client.test.ts b/internal/integration/client.test.ts index bb33339d..a9e55bb0 100644 --- a/internal/integration/client.test.ts +++ b/internal/integration/client.test.ts @@ -46,6 +46,15 @@ test("create", async () => { expect(user.id).toBeGreaterThan(0); }); +test("updateAll", async () => { +await c.queryTag().deleteAll(); +let t = await c.queryTag().create({name:"name",right: true}); +let all=await c.queryTag().where(c.tagName.eq(t.name)).where(c.tagRight.eq(true)).updateAll({name:"name1",right: false}); +expect(all).toBeGreaterThan(0); +let exists=await c.queryTag().where(c.tagName.eq("name1")).exists() +expect(exists).toEqual(true); +}); + test("insertAll", async () => { await c.queryPost().deleteAll(); await expect(async () => { @@ -397,8 +406,8 @@ test("changeJSON", async () => { }); test("modelJSON", async () => { - let tag = await c.queryTag().create({ name: "test" }); - expect(JSON.stringify(tag)).toEqual(`{"id":${tag.id},"name":"test"}`); + let tag = await c.queryTag().create({ name: "test",right: true }); + expect(JSON.stringify(tag)).toEqual(`{"id":${tag.id},"name":"test","right":true}`); }); test("modelString", async () => { diff --git a/internal/integration/client_test.go b/internal/integration/client_test.go index 76ae7174..1b2e3d42 100644 --- a/internal/integration/client_test.go +++ b/internal/integration/client_test.go @@ -74,7 +74,7 @@ func TestCreate(t *testing.T) { require.True(t, user.ID > 0) } -func TestInsertAll(t *testing.T) { +func TestUpdateAll(t *testing.T) { _, err := c.QueryTag().DeleteAll() require.NoError(t, err) @@ -87,7 +87,7 @@ func TestInsertAll(t *testing.T) { require.Equal(t, true, tag.Right.Val) } -func TestUpdateAll(t *testing.T) { +func TestInsertAll(t *testing.T) { _, err := c.QueryUserPost().DeleteAll() require.NoError(t, err) From a0fc4e64b9952dce5abf90f866a5599a2327808c Mon Sep 17 00:00:00 2001 From: liangfujian <50279811+liangfujian@users.noreply.github.com> Date: Tue, 24 Oct 2023 17:01:57 +0800 Subject: [PATCH 07/10] fix action --- internal/integration/client.test.ts | 16 ++++++++-------- internal/integration/client_test.go | 8 ++++---- internal/integration/mysql.hcl | 2 +- internal/integration/postgresql.hcl | 2 +- internal/integration/sqlite.hcl | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/integration/client.test.ts b/internal/integration/client.test.ts index a9e55bb0..0de6d329 100644 --- a/internal/integration/client.test.ts +++ b/internal/integration/client.test.ts @@ -47,12 +47,12 @@ test("create", async () => { }); test("updateAll", async () => { -await c.queryTag().deleteAll(); -let t = await c.queryTag().create({name:"name",right: true}); -let all=await c.queryTag().where(c.tagName.eq(t.name)).where(c.tagRight.eq(true)).updateAll({name:"name1",right: false}); -expect(all).toBeGreaterThan(0); -let exists=await c.queryTag().where(c.tagName.eq("name1")).exists() -expect(exists).toEqual(true); + await c.queryTag().deleteAll(); + await c.queryTag().create({name:"name",right: 1}); + let all=await c.queryTag().where(c.tagName.eq("name")).where(c.tagRight.eq(1)).updateAll({name:"name1",right: 0}); + expect(all).toBeGreaterThan(0); + let exists=await c.queryTag().where(c.tagName.eq("name1")).exists(); + expect(exists).toEqual(true); }); test("insertAll", async () => { @@ -406,8 +406,8 @@ test("changeJSON", async () => { }); test("modelJSON", async () => { - let tag = await c.queryTag().create({ name: "test",right: true }); - expect(JSON.stringify(tag)).toEqual(`{"id":${tag.id},"name":"test","right":true}`); + let tag = await c.queryTag().create({ name: "test",right: 1 }); + expect(JSON.stringify(tag)).toEqual(`{"id":${tag.id},"name":"test","right":1}`); }); test("modelString", async () => { diff --git a/internal/integration/client_test.go b/internal/integration/client_test.go index 1b2e3d42..f4322377 100644 --- a/internal/integration/client_test.go +++ b/internal/integration/client_test.go @@ -78,10 +78,10 @@ func TestUpdateAll(t *testing.T) { _, err := c.QueryTag().DeleteAll() require.NoError(t, err) - tag, err := c.QueryTag().Create(c.ChangeTag().SetRight(true).SetName("name")) + tag, err := c.QueryTag().Create(c.ChangeTag().SetRight(1).SetName("name")) require.NoError(t, err) - all, err := c.QueryTag().Where(c.TagID.EQ(tag.ID)).Where(c.TagRight.EQ(true)).UpdateAll(c.ChangeTag().SetRight(false).SetName("name1")) + all, err := c.QueryTag().Where(c.TagID.EQ(tag.ID)).Where(c.TagRight.EQ(tag.Right.Val)).UpdateAll(c.ChangeTag().SetRight(0).SetName("name1")) require.NoError(t, err) require.True(t, all > 0) require.Equal(t, true, tag.Right.Val) @@ -507,11 +507,11 @@ func TestChangeJSON(t *testing.T) { } func TestModelJSON(t *testing.T) { - tag, err := c.QueryTag().Create(c.ChangeTag().SetName("test").SetRight(true)) + tag, err := c.QueryTag().Create(c.ChangeTag().SetName("test").SetRight(1)) require.NoError(t, err) b, err := json.Marshal(tag) require.NoError(t, err) - require.Equal(t, fmt.Sprintf(`{"id":%d,"name":"test","right":true}`, tag.ID), string(b)) + require.Equal(t, fmt.Sprintf(`{"id":%d,"name":"test","right":1}`, tag.ID), string(b)) } func TestModelStringer(t *testing.T) { diff --git a/internal/integration/mysql.hcl b/internal/integration/mysql.hcl index c0d1c3db..64f37eca 100644 --- a/internal/integration/mysql.hcl +++ b/internal/integration/mysql.hcl @@ -110,7 +110,7 @@ database "db" { } column "right" { - type = boolean + type = integer } index { diff --git a/internal/integration/postgresql.hcl b/internal/integration/postgresql.hcl index 07526b78..68a6e732 100644 --- a/internal/integration/postgresql.hcl +++ b/internal/integration/postgresql.hcl @@ -110,7 +110,7 @@ database "db" { } column "right" { - type = boolean + type = integer } index { diff --git a/internal/integration/sqlite.hcl b/internal/integration/sqlite.hcl index 61ce3489..a689bebf 100644 --- a/internal/integration/sqlite.hcl +++ b/internal/integration/sqlite.hcl @@ -110,7 +110,7 @@ database "db" { } column "right" { - type = boolean + type = integer } index { From 55f17a5d6bd69f8c12e084299a6e81c7a1e6f35c Mon Sep 17 00:00:00 2001 From: liangfujian <50279811+liangfujian@users.noreply.github.com> Date: Tue, 24 Oct 2023 17:21:00 +0800 Subject: [PATCH 08/10] fix action --- internal/integration/client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/integration/client_test.go b/internal/integration/client_test.go index f4322377..3337aeca 100644 --- a/internal/integration/client_test.go +++ b/internal/integration/client_test.go @@ -84,7 +84,7 @@ func TestUpdateAll(t *testing.T) { all, err := c.QueryTag().Where(c.TagID.EQ(tag.ID)).Where(c.TagRight.EQ(tag.Right.Val)).UpdateAll(c.ChangeTag().SetRight(0).SetName("name1")) require.NoError(t, err) require.True(t, all > 0) - require.Equal(t, true, tag.Right.Val) + require.Equal(t, int32(1), tag.Right.Val) } func TestInsertAll(t *testing.T) { From 0b821e429ddd65d3133d977ec66261acbbe69bd5 Mon Sep 17 00:00:00 2001 From: fujian liang <860478944@qq.com> Date: Mon, 25 Dec 2023 11:29:59 +0800 Subject: [PATCH 09/10] fmt tmpl --- generator/client/golang/templates/queryx/update.gotmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/client/golang/templates/queryx/update.gotmpl b/generator/client/golang/templates/queryx/update.gotmpl index a31f8f31..31ea4606 100644 --- a/generator/client/golang/templates/queryx/update.gotmpl +++ b/generator/client/golang/templates/queryx/update.gotmpl @@ -50,7 +50,7 @@ func (s *UpdateStatement) ToSQL() (string, []interface{}) { sets := []string{} for _, col := range s.columns { {{- if eq .client.Adapter "mysql" }} - sets = append(sets, fmt.Sprintf("`%s` = ?", col)) + sets = append(sets, fmt.Sprintf("`%s` = ?", col)) {{- else }} sets = append(sets, fmt.Sprintf("\"%s\" = ?", col)) {{- end }} From 0333d1b02a1854ccb88e87848078abbca350c80d Mon Sep 17 00:00:00 2001 From: fujian liang <860478944@qq.com> Date: Tue, 26 Dec 2023 15:58:54 +0800 Subject: [PATCH 10/10] test delete --- internal/integration/client.test.ts | 6 ++++++ internal/integration/client_test.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/internal/integration/client.test.ts b/internal/integration/client.test.ts index 0de6d329..9b19e46d 100644 --- a/internal/integration/client.test.ts +++ b/internal/integration/client.test.ts @@ -46,6 +46,12 @@ test("create", async () => { expect(user.id).toBeGreaterThan(0); }); +test("delete", async () => { + await c.queryTag().create({ name: "delete_tag", right: 22 }); + let rows = await c.queryTag().where(c.tagRight.eq(22)).deleteAll() + expect(rows).toBeGreaterThan(0); +}); + test("updateAll", async () => { await c.queryTag().deleteAll(); await c.queryTag().create({name:"name",right: 1}); diff --git a/internal/integration/client_test.go b/internal/integration/client_test.go index 3337aeca..b5d01162 100644 --- a/internal/integration/client_test.go +++ b/internal/integration/client_test.go @@ -74,6 +74,14 @@ func TestCreate(t *testing.T) { require.True(t, user.ID > 0) } +func TestDelete(t *testing.T) { + _, err := c.QueryTag().Create(c.ChangeTag().SetRight(22).SetName("delete_tag")) + require.NoError(t, err) + rows, err := c.QueryTag().Where(c.TagRight.EQ(22)).DeleteAll() + require.NoError(t, err) + require.True(t, rows > 0) +} + func TestUpdateAll(t *testing.T) { _, err := c.QueryTag().DeleteAll() require.NoError(t, err)