diff --git a/vlib/orm/orm.v b/vlib/orm/orm.v index 6a6afbb7c5..a6831d1846 100644 --- a/vlib/orm/orm.v +++ b/vlib/orm/orm.v @@ -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 {