mysql2-core 0.3.8 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysql2-core",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "mysql2-core",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/build.ts CHANGED
@@ -59,7 +59,7 @@ export function metadata(attrs: Attributes): Metadata {
59
59
  }
60
60
  return m
61
61
  }
62
- export function buildToSave<T>(obj: T, table: string, attrs: Attributes, ver?: string, buildParam?: (i: number) => string, i?: number): Statement {
62
+ export function buildToSave<T>(obj: T, table: string, attrs: Attributes, buildParam?: (i: number) => string, i?: number): Statement {
63
63
  if (!i) {
64
64
  i = 1
65
65
  }
@@ -86,7 +86,7 @@ export function buildToSave<T>(obj: T, table: string, attrs: Attributes, ver?: s
86
86
  if (v != null && !attr.ignored && !attr.noinsert) {
87
87
  const field = attr.column ? attr.column : k
88
88
  cols.push(field)
89
- if (k === ver) {
89
+ if (attr.version) {
90
90
  isVersion = true
91
91
  values.push(`${1}`)
92
92
  } else {
@@ -99,10 +99,10 @@ export function buildToSave<T>(obj: T, table: string, attrs: Attributes, ver?: s
99
99
  values.push(p)
100
100
  if (typeof v === "boolean") {
101
101
  if (v === true) {
102
- const v2 = attr.true ? attr.true : `'1'`
102
+ const v2 = attr.true !== undefined ? attr.true : `'1'`
103
103
  args.push(v2)
104
104
  } else {
105
- const v2 = attr.false ? attr.false : `'0'`
105
+ const v2 = attr.false !== undefined ? attr.false : `'0'`
106
106
  args.push(v2)
107
107
  }
108
108
  } else {
@@ -112,12 +112,6 @@ export function buildToSave<T>(obj: T, table: string, attrs: Attributes, ver?: s
112
112
  }
113
113
  }
114
114
  }
115
- if (!isVersion && ver && ver.length > 0) {
116
- const attr = attrs[ver]
117
- const field = attr.column ? attr.column : ver
118
- cols.push(field)
119
- values.push(`${1}`)
120
- }
121
115
  if (pks.length === 0) {
122
116
  if (cols.length === 0) {
123
117
  return { query: "", params: args }
@@ -144,10 +138,10 @@ export function buildToSave<T>(obj: T, table: string, attrs: Attributes, ver?: s
144
138
  x = buildParam(i++)
145
139
  if (typeof v === "boolean") {
146
140
  if (v === true) {
147
- const v2 = attr.true ? "" + attr.true : `'1'`
141
+ const v2 = attr.true !== undefined ? attr.true : `'1'`
148
142
  args.push(v2)
149
143
  } else {
150
- const v2 = attr.false ? "" + attr.false : `'0'`
144
+ const v2 = attr.false !== undefined ? attr.false : `'0'`
151
145
  args.push(v2)
152
146
  }
153
147
  } else {
@@ -167,7 +161,7 @@ export function buildToSave<T>(obj: T, table: string, attrs: Attributes, ver?: s
167
161
  }
168
162
  }
169
163
  }
170
- export function buildToSaveBatch<T>(objs: T[], table: string, attrs: Attributes, ver?: string, buildParam?: (i: number) => string): Statement[] {
164
+ export function buildToSaveBatch<T>(objs: T[], table: string, attrs: Attributes, buildParam?: (i: number) => string): Statement[] {
171
165
  if (!buildParam) {
172
166
  buildParam = param
173
167
  }
@@ -186,10 +180,10 @@ export function buildToSaveBatch<T>(objs: T[], table: string, attrs: Attributes,
186
180
  if (v == null) {
187
181
  v = attr.default
188
182
  }
189
- if (v != null && v !== undefined && !attr.ignored && !attr.noinsert) {
183
+ if (v != null && !attr.ignored && !attr.noinsert) {
190
184
  const field = attr.column ? attr.column : k
191
185
  cols.push(field)
192
- if (k === ver) {
186
+ if (attr.version) {
193
187
  isVersion = true
194
188
  values.push(`${1}`)
195
189
  } else {
@@ -202,10 +196,10 @@ export function buildToSaveBatch<T>(objs: T[], table: string, attrs: Attributes,
202
196
  values.push(p)
203
197
  if (typeof v === "boolean") {
204
198
  if (v === true) {
205
- const v2 = attr.true ? attr.true : `'1'`
199
+ const v2 = attr.true !== undefined ? attr.true : `'1'`
206
200
  args.push(v2)
207
201
  } else {
208
- const v2 = attr.false ? attr.false : `'0'`
202
+ const v2 = attr.false !== undefined ? attr.false : `'0'`
209
203
  args.push(v2)
210
204
  }
211
205
  } else {
@@ -215,18 +209,12 @@ export function buildToSaveBatch<T>(objs: T[], table: string, attrs: Attributes,
215
209
  }
216
210
  }
217
211
  }
218
- if (!isVersion && ver && ver.length > 0) {
219
- const attr = attrs[ver]
220
- const field = attr.column ? attr.column : ver
221
- cols.push(field)
222
- values.push(`${1}`)
223
- }
224
212
  const colSet: string[] = []
225
213
  for (const k of ks) {
226
214
  const v = o[k]
227
215
  if (v !== undefined) {
228
216
  const attr = attrs[k]
229
- if (attr && !attr.key && !attr.ignored && k !== ver && !attr.noupdate) {
217
+ if (attr && !attr.key && !attr.ignored && !attr.noupdate) {
230
218
  const field = attr.column ? attr.column : k
231
219
  let x: string
232
220
  if (v === null) {
@@ -239,10 +227,10 @@ export function buildToSaveBatch<T>(objs: T[], table: string, attrs: Attributes,
239
227
  x = buildParam(i++)
240
228
  if (typeof v === "boolean") {
241
229
  if (v === true) {
242
- const v2 = attr.true ? "" + attr.true : `'1'`
230
+ const v2 = attr.true !== undefined ? attr.true : `'1'`
243
231
  args.push(v2)
244
232
  } else {
245
- const v2 = attr.false ? "" + attr.false : `'0'`
233
+ const v2 = attr.false !== undefined ? attr.false : `'0'`
246
234
  args.push(v2)
247
235
  }
248
236
  } else {
@@ -270,4 +258,4 @@ export function toString(v: number): string {
270
258
  return "" + v
271
259
  }
272
260
  return "null"
273
- }
261
+ }