This module provides the base objects used by the sqlite.nim module.
Types
DbBusyError = object of DbError
- Used whenever Exa encounters a SQLITE_BUSY error. Source Edit
DbConn = ref object profile*: DbConnProfile conn*: lib.Sqlite3 cache*: Table[string, Stmt]
-
The main database connection object
- The profile field contains the database connection profile, see DbConnProfile for more information.
- The conn field contains the raw SQLite3 database object, don't mess with this.
- The cache field contains a cache for frequently-used queries, this is meant to enhance performance.
DbConnProfile {.pure.} = enum Default, Minimal, Server
-
This enum allows you to specify a preset of options, the default profile is Minimal which enables WAL and Foreign Keys.
- Default doesn't activate any options. It leaves you alone with SQLite's defaults.
- Minimal enables enables WAL and Foreign Keys, this allows for greater concurrency when using SQLite anywhere but a network. Ideally used for short-lived database connections.
- Server enables WAL, foreign keys and also synchronous mode along with other options that are usually great for web servers. Ideally used for long-lived database connections.
DbError = object of CatchableError
- Whenever exa encounters an error, it'll usually raise an exception where needed with this type. Source Edit
DbPool = object conns*: seq[DbConn] lock*: Lock cond*: Cond
-
This object is what's behind the "Connection pool" feature that exa has.
- conns is a sequence of database connections. (See DbConn)
- lock is a lock, used for mutexes.
- cond is a condition variable, used for signalling.
DbRow = seq[DbValue]
- This object is meant to represent a single, individual row, it may contain any number of database values, one for each column. Source Edit
DbValue = object case kind*: DbValueKind of Text: strVal*: string of Integer: intVal*: int64 of Blob: blobVal*: seq[byte] of Float: floatVal*: float64 of Null: nil
-
This is a "database value" object, it basically represents all of the types supported by SQLite in a single object.
This is what you will be getting from iterate(), one() and all() wrapped in a little DbRow, you can access the fields to actually get the data in the value.
Source Edit DbValueKind {.pure.} = enum Text, Integer, Blob, Float, Null
-
This enum is used to denote types in database values (and rows)
- Text is for string values.
- Integer is for, well... integers.
- Blob is for binary data, usually a seq[byte]
- Float is for floating point numbers.
- Null which is meant to represent the NULL value in SQL.