Skip to content

Commit 8b5786c

Browse files
committed
add tests
1 parent 3b00bbf commit 8b5786c

File tree

1 file changed

+83
-5
lines changed

1 file changed

+83
-5
lines changed

builder_test.go

+83-5
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,11 @@ func TestGenerateUpsertSQL(t *testing.T) {
419419

420420

421421

422-
// type Assoc1 struct {
423-
// TableName struct{} `db:"assoc_table"`
424-
// F1 int `db:"f1,unique"`
425-
// F2 int `db:"f2,unique"`
426-
// }
422+
// type Assoc1 struct {
423+
// TableName struct{} `db:"assoc_table"`
424+
// F1 int `db:"f1,unique"`
425+
// F2 int `db:"f2,unique"`
426+
// }
427427
{
428428
dbType: gobatis.Postgres,
429429
value: Assoc1{},
@@ -433,6 +433,14 @@ func TestGenerateUpsertSQL(t *testing.T) {
433433
sql: "INSERT INTO assoc_table(f1, f2) VALUES(#{f1}, #{f2}) ON CONFLICT (f1, f2) DO NOTHING ",
434434
},
435435

436+
{
437+
dbType: gobatis.Postgres,
438+
value: Assoc1{},
439+
keyNames: []string{},
440+
argNames: []string{"a"},
441+
argTypes: []reflect.Type{reflect.TypeOf(new(Assoc1)).Elem()},
442+
sql: "INSERT INTO assoc_table(f1, f2) VALUES(#{f1}, #{f2}) ON CONFLICT (f1, f2) DO NOTHING ",
443+
},
436444

437445
{
438446
dbType: gobatis.MSSql,
@@ -443,6 +451,15 @@ func TestGenerateUpsertSQL(t *testing.T) {
443451
sql: "MERGE INTO assoc_table AS t USING ( VALUES(#{f1}, #{f2} ) ) AS s (f1, f2 ) ON t.f1 = s.f1 AND t.f2 = s.f2 WHEN NOT MATCHED THEN INSERT (f1, f2) VALUES(s.f1, s.f2) ;",
444452
},
445453

454+
{
455+
dbType: gobatis.MSSql,
456+
value: Assoc1{},
457+
keyNames: []string{},
458+
argNames: []string{"a"},
459+
argTypes: []reflect.Type{reflect.TypeOf(new(Assoc1)).Elem()},
460+
sql: "MERGE INTO assoc_table AS t USING ( VALUES(#{f1}, #{f2} ) ) AS s (f1, f2 ) ON t.f1 = s.f1 AND t.f2 = s.f2 WHEN NOT MATCHED THEN INSERT (f1, f2) VALUES(s.f1, s.f2) ;",
461+
},
462+
446463
{
447464
dbType: gobatis.Oracle,
448465
value: Assoc1{},
@@ -452,6 +469,15 @@ func TestGenerateUpsertSQL(t *testing.T) {
452469
sql: "MERGE INTO assoc_table AS t USING dual ON t.f1= #{f1} AND t.f2= #{f2} WHEN NOT MATCHED THEN INSERT (f1, f2) VALUES(#{f1}, #{f2}) ",
453470
},
454471

472+
{
473+
dbType: gobatis.Oracle,
474+
value: Assoc1{},
475+
keyNames: []string{},
476+
argNames: []string{"a"},
477+
argTypes: []reflect.Type{reflect.TypeOf(new(Assoc1)).Elem()},
478+
sql: "MERGE INTO assoc_table AS t USING dual ON t.f1= #{f1} AND t.f2= #{f2} WHEN NOT MATCHED THEN INSERT (f1, f2) VALUES(#{f1}, #{f2}) ",
479+
},
480+
455481

456482
// {
457483
// dbType: gobatis.Mysql,
@@ -477,6 +503,14 @@ func TestGenerateUpsertSQL(t *testing.T) {
477503
argTypes: []reflect.Type{_intType, _intType},
478504
sql: "INSERT INTO assoc_table(f1, f2) VALUES(#{f1}, #{f2}) ON CONFLICT (f1, f2) DO NOTHING RETURNING id",
479505
},
506+
{
507+
dbType: gobatis.Postgres,
508+
value: Assoc2{},
509+
keyNames: []string{},
510+
argNames: []string{"a"},
511+
argTypes: []reflect.Type{reflect.TypeOf(new(Assoc2)).Elem()},
512+
sql: "INSERT INTO assoc_table(f1, f2) VALUES(#{f1}, #{f2}) ON CONFLICT (f1, f2) DO NOTHING RETURNING id",
513+
},
480514

481515
{
482516
dbType: gobatis.MSSql,
@@ -486,6 +520,14 @@ func TestGenerateUpsertSQL(t *testing.T) {
486520
argTypes: []reflect.Type{_intType, _intType},
487521
sql: "MERGE INTO assoc_table AS t USING ( VALUES(#{f1}, #{f2} ) ) AS s (f1, f2 ) ON t.f1 = s.f1 AND t.f2 = s.f2 WHEN NOT MATCHED THEN INSERT (f1, f2) VALUES(s.f1, s.f2) OUTPUT inserted.id;",
488522
},
523+
{
524+
dbType: gobatis.MSSql,
525+
value: Assoc2{},
526+
keyNames: []string{},
527+
argNames: []string{"a"},
528+
argTypes: []reflect.Type{reflect.TypeOf(new(Assoc2)).Elem()},
529+
sql: "MERGE INTO assoc_table AS t USING ( VALUES(#{f1}, #{f2} ) ) AS s (f1, f2 ) ON t.f1 = s.f1 AND t.f2 = s.f2 WHEN NOT MATCHED THEN INSERT (f1, f2) VALUES(s.f1, s.f2) OUTPUT inserted.id;",
530+
},
489531

490532
{
491533
dbType: gobatis.Oracle,
@@ -495,6 +537,14 @@ func TestGenerateUpsertSQL(t *testing.T) {
495537
argTypes: []reflect.Type{_intType, _intType},
496538
sql: "MERGE INTO assoc_table AS t USING dual ON t.f1= #{f1} AND t.f2= #{f2} WHEN NOT MATCHED THEN INSERT (f1, f2) VALUES(#{f1}, #{f2}) ",
497539
},
540+
{
541+
dbType: gobatis.Oracle,
542+
value: Assoc2{},
543+
keyNames: []string{},
544+
argNames: []string{"a"},
545+
argTypes: []reflect.Type{reflect.TypeOf(new(Assoc2)).Elem()},
546+
sql: "MERGE INTO assoc_table AS t USING dual ON t.f1= #{f1} AND t.f2= #{f2} WHEN NOT MATCHED THEN INSERT (f1, f2) VALUES(#{f1}, #{f2}) ",
547+
},
498548

499549
// {
500550
// dbType: gobatis.Mysql,
@@ -568,6 +618,16 @@ func TestGenerateUpsertSQL(t *testing.T) {
568618
sql: "INSERT INTO assoc_table(f1, f2, created_at, updated_at) VALUES(#{f1}, #{f2}, now(), now()) ON CONFLICT (f1, f2) DO UPDATE SET updated_at=EXCLUDED.updated_at RETURNING id",
569619
},
570620

621+
622+
{
623+
dbType: gobatis.Postgres,
624+
value: Assoc4{},
625+
keyNames: []string{},
626+
argNames: []string{"a"},
627+
argTypes: []reflect.Type{reflect.TypeOf(new(Assoc4)).Elem()},
628+
sql: "INSERT INTO assoc_table(f1, f2, created_at, updated_at) VALUES(#{f1}, #{f2}, now(), now()) ON CONFLICT (f1, f2) DO UPDATE SET updated_at=EXCLUDED.updated_at RETURNING id",
629+
},
630+
571631
{
572632
dbType: gobatis.MSSql,
573633
value: Assoc4{},
@@ -577,6 +637,16 @@ func TestGenerateUpsertSQL(t *testing.T) {
577637
sql: "MERGE INTO assoc_table AS t USING ( VALUES(#{f1}, #{f2}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP ) ) AS s (f1, f2, created_at, updated_at ) ON t.f1 = s.f1 AND t.f2 = s.f2 WHEN MATCHED THEN UPDATE SET updated_at = s.updated_at WHEN NOT MATCHED THEN INSERT (f1, f2, created_at, updated_at) VALUES(s.f1, s.f2, s.created_at, s.updated_at) OUTPUT inserted.id;",
578638
},
579639

640+
641+
{
642+
dbType: gobatis.MSSql,
643+
value: Assoc4{},
644+
keyNames: []string{},
645+
argNames: []string{"a"},
646+
argTypes: []reflect.Type{reflect.TypeOf(new(Assoc4)).Elem()},
647+
sql: "MERGE INTO assoc_table AS t USING ( VALUES(#{f1}, #{f2}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP ) ) AS s (f1, f2, created_at, updated_at ) ON t.f1 = s.f1 AND t.f2 = s.f2 WHEN MATCHED THEN UPDATE SET updated_at = s.updated_at WHEN NOT MATCHED THEN INSERT (f1, f2, created_at, updated_at) VALUES(s.f1, s.f2, s.created_at, s.updated_at) OUTPUT inserted.id;",
648+
},
649+
580650
{
581651
dbType: gobatis.Oracle,
582652
value: Assoc4{},
@@ -585,6 +655,14 @@ func TestGenerateUpsertSQL(t *testing.T) {
585655
argTypes: []reflect.Type{_intType, _intType},
586656
sql: "MERGE INTO assoc_table AS t USING dual ON t.f1= #{f1} AND t.f2= #{f2} WHEN MATCHED THEN UPDATE SET updated_at= CURRENT_TIMESTAMP WHEN NOT MATCHED THEN INSERT (f1, f2, created_at, updated_at) VALUES(#{f1}, #{f2}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) ",
587657
},
658+
{
659+
dbType: gobatis.Oracle,
660+
value: Assoc4{},
661+
keyNames: []string{},
662+
argNames: []string{"a"},
663+
argTypes: []reflect.Type{reflect.TypeOf(new(Assoc4)).Elem()},
664+
sql: "MERGE INTO assoc_table AS t USING dual ON t.f1= #{f1} AND t.f2= #{f2} WHEN MATCHED THEN UPDATE SET updated_at= CURRENT_TIMESTAMP WHEN NOT MATCHED THEN INSERT (f1, f2, created_at, updated_at) VALUES(#{f1}, #{f2}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) ",
665+
},
588666

589667
// {
590668
// dbType: gobatis.Mysql,

0 commit comments

Comments
 (0)