@@ -377,6 +377,81 @@ func ExampleInsertDataset_Rows_withGoquSkipInsertTag() {
377377 // INSERT INTO "items" ("address") VALUES ('111 Test Addr'), ('112 Test Addr') []
378378}
379379
380+ func ExampleInsertDataset_Rows_withOmitNilTag () {
381+ type item struct {
382+ FirstName string `db:"first_name" goqu:"omitnil"`
383+ LastName string `db:"last_name" goqu:"omitnil"`
384+ Address1 * string `db:"address1" goqu:"omitnil"`
385+ Address2 * string `db:"address2" goqu:"omitnil"`
386+ Address3 * string `db:"address3" goqu:"omitnil"`
387+ }
388+ address1 := "111 Test Addr"
389+ var emptyString string
390+ i := item {
391+ FirstName : "Test First Name" ,
392+ LastName : "" ,
393+ Address1 : & address1 ,
394+ Address2 : & emptyString ,
395+ Address3 : nil , // will omit nil pointer
396+ }
397+
398+ insertSQL , args , _ := goqu .Insert ("items" ).Rows (i ).ToSQL ()
399+ fmt .Println (insertSQL , args )
400+
401+ // Output:
402+ // INSERT INTO "items" ("address1", "address2", "first_name", "last_name") VALUES ('111 Test Addr', '', 'Test First Name', '') []
403+ }
404+
405+ func ExampleInsertDataset_Rows_withOmitEmptyTag () {
406+ type item struct {
407+ FirstName string `db:"first_name" goqu:"omitempty"`
408+ LastName string `db:"last_name" goqu:"omitempty"`
409+ Address1 * string `db:"address1" goqu:"omitempty"`
410+ Address2 * string `db:"address2" goqu:"omitempty"`
411+ Address3 * string `db:"address3" goqu:"omitempty"`
412+ }
413+ address1 := "112 Test Addr"
414+ var emptyString string
415+ i := item {
416+ FirstName : "Test First Name" ,
417+ LastName : "" , // will omit zero field
418+ Address1 : & address1 ,
419+ Address2 : & emptyString ,
420+ Address3 : nil , // will omit nil pointer
421+ }
422+ insertSQL , args , _ := goqu .Insert ("items" ).Rows (i ).ToSQL ()
423+ fmt .Println (insertSQL , args )
424+
425+ // Output:
426+ // INSERT INTO "items" ("address1", "address2", "first_name") VALUES ('112 Test Addr', '', 'Test First Name') []
427+ }
428+
429+ func ExampleInsertDataset_Rows_withOmitEmptyTag_Valuer () {
430+ type item struct {
431+ FirstName sql.NullString `db:"first_name" goqu:"omitempty"`
432+ MiddleName sql.NullString `db:"middle_name" goqu:"omitempty"`
433+ LastName sql.NullString `db:"last_name" goqu:"omitempty"`
434+ Address1 * sql.NullString `db:"address1" goqu:"omitempty"`
435+ Address2 * sql.NullString `db:"address2" goqu:"omitempty"`
436+ Address3 * sql.NullString `db:"address3" goqu:"omitempty"`
437+ Address4 * sql.NullString `db:"address4" goqu:"omitempty"`
438+ }
439+ i := item {
440+ FirstName : sql.NullString {Valid : true , String : "Test First Name" },
441+ MiddleName : sql.NullString {Valid : true , String : "" },
442+ LastName : sql.NullString {}, // will omit zero valuer struct
443+ Address1 : & sql.NullString {Valid : true , String : "Test Address 1" },
444+ Address2 : & sql.NullString {Valid : true , String : "" },
445+ Address3 : & sql.NullString {},
446+ Address4 : nil , // will omit nil pointer
447+ }
448+ insertSQL , args , _ := goqu .Insert ("items" ).Rows (i ).ToSQL ()
449+ fmt .Println (insertSQL , args )
450+
451+ // Output:
452+ // INSERT INTO "items" ("address1", "address2", "address3", "first_name", "middle_name") VALUES ('Test Address 1', '', NULL, 'Test First Name', '') []
453+ }
454+
380455func ExampleInsertDataset_Rows_withGoquDefaultIfEmptyTag () {
381456 type item struct {
382457 ID uint32 `goqu:"skipinsert"`
0 commit comments