@@ -65,12 +65,47 @@ ins := sqlinsert.Insert{`candy`, &rec}
65
65
_ , err := ins.Insert (db)
66
66
```
67
67
68
- ## This is not an ORM
68
+ ### I want to see the SQL
69
+ Question-mark (?) VALUES-tokens are the default:
70
+ ``` go
71
+ fmt.Println (ins.SQL ())
72
+ // INSERT INTO candy (id,candy_name,form_factor,description,manufacturer,weight_grams,ts) VALUES (?,?,?,?,?,?,?)
73
+ ```
74
+
75
+ You can change the token type. For example, for PostgreSQL:
76
+ ``` go
77
+ sqlinsert.UseTokenType = OrdinalNumberTokenType
78
+ fmt.Println (ins.SQL ())
79
+ // INSERT INTO candy (id,candy_name,form_factor,description,manufacturer,weight_grams,ts) VALUES ($1,$2,$3,$4,$5,$6,$7)
80
+ ```
81
+
82
+ ### I want to see the args
83
+
84
+ ``` go
85
+ pretty.Println (ins.Args ())
86
+ ```
87
+ yields (using [ github.com/kr/pretty] ( https://github.com/kr/pretty ) ):
88
+ ```
89
+ []interface {}{
90
+ "c0600afd-78a7-4a1a-87c5-1bc48cafd14e",
91
+ "Gougat",
92
+ "Package",
93
+ "tastes like gopher feed",
94
+ "Gouggle",
95
+ float64(1.1618),
96
+ time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
97
+ }
98
+ ```
99
+
100
+ ### I want to use database/sql apparatus
101
+ ``` go
102
+ stmt , _ := db.Prepare (ins.SQL ())
103
+ result , _ := stmt.Exec (ins.Args ()...)
104
+ ```
105
+
106
+
107
+ ## This is a helper
69
108
70
- ### Hide nothing
71
- Unlike ORMs, ` sqlinsert ` does ** not** create an abstraction layer over SQL relations, nor does it restructure SQL
72
- functions.
73
- The aim is to keep it simple and hide nothing.
74
109
` sqlinsert ` is fundamentally a helper for [ database/sql] ( https://pkg.go.dev/database/sql ) .
75
110
It simply maps struct fields to INSERT elements:
76
111
* struct tags
@@ -88,7 +123,12 @@ All aspects of SQL INSERT remain in your control:
88
123
* _ I just want the bind args for my Exec() call._ ` Insert.Args() `
89
124
* _ I just want a Prepare-Exec wrapper._ ` Insert.Insert() `
90
125
91
- ## This is a helper
126
+ ## This is not an ORM
127
+
128
+ ### Hide nothing
129
+ Unlike ORMs, ` sqlinsert ` does ** not** create an abstraction layer over SQL relations, nor does it restructure SQL
130
+ functions.
131
+ The aim is to keep it simple and hide nothing.
92
132
93
133
### Let SQL be great
94
134
SQL’s INSERT is already as close to functionally pure as possible. Why would we change that? Its simplicity and
0 commit comments