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

examples, orm: fix orm example; add -d trace_orm option to see all ORM generated queries (#17770)

* orm: add tracing of the generated queries by the orm module, when a program is compiled with `-d trace_orm`

* examples: fix examples/database/orm.v, add comments, and ensure that the example can be run several times with no errors

The example demonstrates connecting to all 3 DBs in the same program, and will be added to the CI very soon,
to serve both as a regression test, if it fails, and as an example to how to use the ORM in combination with
raw SQL queries to the DBs (which are driver/wrapper specific, unlike the ORM, but can be more convenient in some situations).
This commit is contained in:
Delyan Angelov
2023-03-25 21:46:17 +02:00
committed by GitHub
parent f5f45d846e
commit db97630117
2 changed files with 153 additions and 92 deletions

View File

@ -305,6 +305,12 @@ pub fn orm_stmt_gen(sql_dialect SQLDialect, table string, q string, kind StmtKin
}
}
str += ';'
$if trace_orm_stmt ? {
eprintln('> orm_stmt sql_dialect: ${sql_dialect} | table: ${table} | kind: ${kind} | query: ${str}')
}
$if trace_orm ? {
eprintln('> orm: ${str}')
}
return str, QueryData{
fields: data_fields
data: data_data
@ -393,6 +399,12 @@ pub fn orm_select_gen(orm SelectConfig, q string, num bool, qm string, start_pos
}
str += ';'
$if trace_orm_query ? {
eprintln('> orm_query: ${str}')
}
$if trace_orm ? {
eprintln('> orm: ${str}')
}
return str
}
@ -515,6 +527,12 @@ pub fn orm_table_gen(table string, q string, defaults bool, def_unique_len int,
fs << unique_fields
str += fs.join(', ')
str += ');'
$if trace_orm_create ? {
eprintln('> orm_create table: ${table} | query: ${str}')
}
$if trace_orm ? {
eprintln('> orm: ${str}')
}
return str
}