ozark/query

Search:
Group by:

Types

OzarkModelDefect = object of CatchableError

Procs

proc `$`(sql: SqlQuery): string {....raises: [], tags: [], forbids: [].}
proc tryInsertID(db: DbConn; query: SqlPrepared; args: varargs[string, `$`]): int64 {.
    ...tags: [WriteDbEffect], raises: [DbError, ValueError], forbids: [].}
executes the query (typically "INSERT") and returns the generated ID for the row or -1 in case of an error. For Postgre this adds RETURNING id to the query, so it only works if your primary key is named id.

Macros

macro dropTable(modelName: untyped; cascade: static bool = false): untyped
Compile-time macro to drop a model's table from the database.
macro exec(sql: untyped)
Finalize and execute an SQL statement that doesn't return results (e.g. INSERT, UPDATE, DELETE).
macro execGet(sql: untyped): untyped

Finalize and execute an SQL statement that returns results (e.g. SELECT, INSERT with RETURNING).

This macro produces the final SQL string and wraps it in a runtime call

macro exists(tableName: untyped)
Search in the current table for a record matching the specified values. This is a placeholder for an EXISTS query.
macro get(sql: untyped): untyped
Finalize SQL statement. This macro produces the final SQL string and emits runtime code that maps selected columns into a new instance of m
macro getAll(sql: untyped): untyped
Finalize and get all results of the SQL statement. This macro produce the final SQL string and wraps it in a runtime call to execute it and return all rows via instantRows
macro insert(tableName, data: untyped): untyped
Placeholder for an INSERT statement. This macro generates the SQL string for the INSERT statement. This macro performs compile-time checks for the existence of the specified model and the validity of the column names.
macro limit(sql: untyped; count: untyped): untyped
Placeholder for a LIMIT clause in SQL queries.
macro orderBy(sql: untyped; col: static string; desc: static bool = false): untyped
Placeholder for an ORDER BY clause in SQL queries.
macro orWhere(sql: untyped; col: static string; val: untyped): untyped
Define OR in WHERE clause
macro orWhereNot(sql: untyped; col: static string; val: untyped): untyped
Define a OR condition with NOT in WHERE clause
macro prepareTable(modelName): untyped

Compile-time macro to prepare a model's table in the database.

This macro generates the SQL string for creating the table based on the model definition and executes it at compile time to ensure the table exists before any queries are made against it.

macro rawSQL(models: ptr ModelsTable; sql: static string;
             values: varargs[untyped]): untyped
Allows raw SQL queries without losing safety of model checks (table name/column names) and SQL validation at compile time
macro removeRow(tableName: untyped): untyped
Placeholder for a DELETE statement. This macro generates the SQL string for the DELETE statement. This macro performs compile-time checks for the existence of the specified model.
macro select(tableName: untyped; col: static string): untyped
Define SELECT clause
macro select(tableName: untyped; cols: static openArray[string]): untyped
Define SELECT clause with specific columns.
macro selectAll(tableName: untyped): untyped
Define SELECT * clause
macro update(tableName, data: untyped): untyped
Placeholder for an UPDATE statement. This macro generates the SQL string for the UPDATE statement. This macro performs compile-time checks for the existence of the specified model and the validity of the column names.
macro where(sql: untyped; col: static string; val: untyped): untyped
Define WHERE clause
macro whereEndsLike(sql: untyped; col: static string; val: untyped): untyped
Define WHERE clause with LIKE for suffix matching
macro whereIn(sql: untyped; col: static string; vals: untyped): untyped
Define WHERE clause with IN operator
macro whereLike(sql: untyped; col: static string; val: untyped): untyped
Define WHERE clause with LIKE for any position
macro whereNot(sql: untyped; col: static string; val: untyped): untyped
Define WHERE clause with NOT
macro whereNotEndsLike(sql: untyped; col: static string; val: untyped): untyped
Define WHERE clause with NOT LIKE for suffix matching
macro whereNotIn(sql: untyped; col: static string; vals: untyped): untyped
Define WHERE clause with NOT IN operator
macro whereNotLike(sql: untyped; col: static string; val: untyped): untyped
Define WHERE clause with NOT LIKE for any position
macro whereNotStartsLike(sql: untyped; col: static string; val: untyped): untyped
Define WHERE clause with NOT LIKE for prefix matching
macro whereStartsLike(sql: untyped; col: static string; val: untyped): untyped
Define WHERE clause with LIKE for prefix matching

Templates

template table(models: ptr ModelsTable; name): untyped
Define SQL statement for a table
template withTableCheck(name: NimNode; body)
Check if a model with the given name exists in the Models table.