1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

orm: refactor insert part of orm_stmt_gen (#11121)

This commit is contained in:
Shobi 2021-08-10 22:31:09 +02:00 committed by GitHub
parent da53f818df
commit 012b3f0f64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -136,24 +136,22 @@ pub fn orm_stmt_gen(table string, para string, kind StmtKind, num bool, qm strin
match kind {
.insert {
str += 'INSERT INTO $para$table$para ('
for i, field in data.fields {
str += '$para$field$para'
if i < data.fields.len - 1 {
str += ', '
}
}
str += ') VALUES ('
for i, _ in data.fields {
str += qm
mut values := []string{}
for _ in 0 .. data.fields.len {
// loop over the length of data.field and generate ?0, ?1 or just ? based on the $num parameter for value placeholders
if num {
str += '$c'
values << '$qm$c'
c++
}
if i < data.fields.len - 1 {
str += ', '
} else {
values << '$qm'
}
}
str += 'INSERT INTO $para$table$para ('
str += data.fields.map('$para$it$para').join(', ')
str += ') VALUES ('
str += values.join(', ')
str += ')'
}
.update {