# src/allographer/query_builder/libs/sqlite/sqlite_lib

Theme:

- Index

Search:
Group by:

# Imports

../../error, ../../models/database_types, sqlite_rdb

# Procs

    proc `[]`(row: InstantRow; col: int32): string {.inline, ...raises: [], tags: [],
        forbids: [].}

  Returns text for given column of the row.

  See also:

  - instantRows iterator example code

    proc bindParam(ps: PStmt; paramIdx: int; val: string; copy = true) {.
        ...raises: [DbError], tags: [], forbids: [].}

  Binds a string to the specified paramIndex. if copy is true then SQLite makes its own private copy of the data immediately

    proc dbError(db: PSqlite3) {.noreturn, ...raises: [DbError], tags: [], forbids: [].}

  Raises a `DbError` exception.

  Examples:

      let db = open("mytest.db", "", "", "")
      if not db.tryExec(sql"SELECT * FROM not_exist_table"):
        dbError(db)
      db.close()

    proc dbFormat(formatstr: string; args: varargs[string]): string {....raises: [],
        tags: [], forbids: [].}

    proc getColumns(db: PSqlite3; dbRows: var DbRows; query: string;
                    args: seq[string]): seq[string] {....raises: [DbError, DbError],
        tags: [], forbids: [].}

    proc len(row: InstantRow): int32 {.inline, ...raises: [], tags: [], forbids: [].}

  Returns number of columns in a row.

  See also:

  - instantRows iterator example code

    proc sqliteQuoteIdent(name: string): string {....raises: [], tags: [], forbids: [].}

  `PRAGMA` 等で使う SQLite の二重引用符識別子（内部の `"` は `""` にエスケープ）。

# Iterators

    iterator instantRows(db: PSqlite3; dbRows: var DbRows; query: string;
                         args: seq[string]): InstantRow {....tags: [ReadDbEffect],
        raises: [DbError, DbError], forbids: [].}

  Similar to instantRows iterator, but sets information about columns to `columns`.

  Examples:

      let db = open("mytest.db", "", "", "")

      # Records of my_table:
      # | id | name     |
      # |----|----------|
      # |  1 | item#1   |
      # |  2 | item#2   |

      var columns: DbColumns
      for row in db.instantRows(columns, sql"SELECT * FROM my_table"):
        discard
      echo columns[0]

      # Output:
      # (name: "id", tableName: "my_table", typ: (kind: dbNull,
      # notNull: false, name: "INTEGER", size: 0, maxReprLen: 0, precision: 0,
      # scale: 0, min: 0, max: 0, validValues: @[]), primaryKey: false,
      # foreignKey: false)

      db.close()

    iterator instantRows(db: PSqlite3; dbRows: var DbRows; sqliteStmt: PStmt): InstantRow {.
        ...tags: [ReadDbEffect, WriteDbEffect], raises: [DbError], forbids: [].}

    iterator instantRowsPlain(db: PSqlite3; query: string; args: seq[string]): InstantRow {.
        ...tags: [ReadDbEffect], raises: [DbError, DbError], forbids: [].}

# Templates

    template dbBindParamError(paramIdx: int; val: varargs[untyped])

  Raises a `DbError` exception.