Import std.db.database
std.db.database
std.db: SQLite databases, through the runtime's fb_db_ functions. A Database runs SQL with its
parameters bound to values, and gives the Rows a query reads, or with Query<T> each as a T
that Load<T> makes of its columns; Prepare makes a Statement to run many times, Begin a
Transaction, which keeps all of what it does or none of it, and Migrate brings a database up to
date, a numbered migration at a time. What SQLite can't do throws a DatabaseError of its kind,
with SQLite's message.
std/db/database.fb
Types
ColumnType
enum
Public Enum ColumnType
SQLite's types of values: which one a Row's column holds.
-
An integer, as an Int64.
-
A floating-point number, as a Double.
-
Text, as a String.
-
Bytes, as a UInt8[].
-
No value.
SqlValue
interface
Public Interface SqlValue
What a statement's parameter takes: an integer, a Bool as 1 or 0, a Float32 or Float64 as a real, but for NaN, a String as text, a UInt8[] as a blob, or a Nullable, NULL when its value is Null. A type of the program's is one too when its BindTo binds one of these, with statement.Bind(index, value).
-
Binds
statement's parameter atindex, from 1, to the value.
Nullable
struct
Public Struct Nullable<T: SqlValue> Implements SqlValue
A value that may be Null, for a parameter that's NULL when it is: Nullable(name) for a String? name.
-
The value, or Null for SQL's NULL.
-
A Nullable of
value.
Row
struct
Public Struct Row
A row a query read: its columns' names and values, which Integer, Real, Text, and Blob give by the column's index, from 0, or its name, as the SQL gives it, like "id" or "count(*)". Each gives Null for NULL, and panics for a value of another type, but Real takes an integer too, so a column of either reads as one. Type says which a column holds. A name that two columns have is the first's.
-
How many columns it has.
-
The name of the
columnat index. Panics when there's none there. -
The type of the
columnatcolumn's value. Panics when there's none there. -
The type of the column named
name's value. Panics when there's none of thatname. -
Whether the
columnatcolumnis NULL. Panics when there's none there. -
Whether the column named
nameis NULL. Panics when there's none of thatname. -
The integer at
column, or Null for NULL. Panics when there's no column there, or it's of another type. -
The integer in the column named
name, or Null for NULL. Panics when there's no column of thatname, or it's of another type. -
The real number at
column, an integer's too, or Null for NULL. Panics when there's nocolumnthere, or it's of another type. -
The real number in the column named
name, an integer's too, or Null for NULL. Panics when there's no column of thatname, or it's of another type. -
The text at
column, or Null for NULL. Panics when there's no column there, or it's of another type. -
The text in the column named
name, or Null for NULL. Panics when there's no column of thatname, or it's of another type. -
The blob at
column, or Null for NULL. Panics when there's no column there, or it's of another type. -
The blob in the column named
name, or Null for NULL. Panics when there's no column of thatname, or it's of another type.
Database
class
Public Class Database
A connection to an SQLite database, which closes when Close is called, or when its last reference goes, and those of its Statements and Transactions. One thread uses it at a time.
-
The database at
path, made when there's none: a file, ":memory:" for a new one in memory that only this Database reaches, or a URI file name, like "file:data.db?mode=ro" to only read one, or "file:name?mode=memory&cache=shared" for one in memory that each Database of that name shares while one is open. Its foreign keys are checked, and it waits up to 5 seconds for another connection that holds the database before it throws a DatabaseError of BUSY. -
Closes it now, and rolls back what an open Transaction did, as its last reference going would, and finalizes its Statements, so it lets go of its file and locks then. Using it, or them, after that panics, but for Close, which does nothing then.
-
Whether Close has closed it.
-
How many rows the last INSERT, UPDATE, or DELETE changed.
-
The rowid of the last row an INSERT added, or 0 before one has.
-
Runs each statement in
sql, in turn, and throws what the first that fails fails with, leaving what the ones before it did, but for what a Transaction undoes. Panics when one takes parameters, which Execute(sql, values) binds. -
Runs
sql's one statement with its parameters bound to values, in order, a value for each, as a Statement's Execute does. Throws a DatabaseError of QUERY whensqlisn't one statement. -
Runs
sql's one statement with its parameters bound toathroughb, in order, as the one that takesaalone does. -
@PanicsAtCaller Public Method Execute<A, B, C>(sql: String, a: A, b: B, c: C) Throws DatabaseErrormethod #Runs
sql's one statement with its parameters bound toathroughc, in order, as the one that takesaalone does. -
@PanicsAtCaller Public Method Execute<A, B, C, D>(sql: String, a: A, b: B, c: C, d: D) Throws DatabaseErrormethod #Runs
sql's one statement with its parameters bound toathroughd, in order, as the one that takesaalone does. -
@PanicsAtCaller Public Method Execute<A, B, C, D, E>(sql: String, a: A, b: B, c: C, d: D, e: E) Throws DatabaseErrormethod #Runs
sql's one statement with its parameters bound toathroughe, in order, as the one that takesaalone does. -
@PanicsAtCaller Public Method Execute<A, B, C, D, E, F>(sql: String, a: A, b: B, c: C, d: D, e: E, f: F) Throws DatabaseErrormethod #Runs
sql's one statement with its parameters bound toathroughf, in order, as the one that takesaalone does. -
@PanicsAtCaller Public Method Execute<A, B, C, D, E, F, G>(sql: String, a: A, b: B, c: C, d: D, e: E, f: F, g: G) Throws DatabaseErrormethod #Runs
sql's one statement with its parameters bound toathroughg, in order, as the one that takesaalone does. -
@PanicsAtCaller Public Method Execute<A, B, C, D, E, F, G, H>(sql: String, a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H) Throws DatabaseErrormethod #Runs
sql's one statement with its parameters bound toathroughh, in order, as the one that takesaalone does. -
The rows
sql's one query reads, with its parameters bound to values as Execute's are, so Rows(sql) panics when it takes any. -
The rows
sql's one query reads, each a T, as a Statement'sQuery<T>()gives them. Panics whensqltakes parameters, which a Statement binds. -
@PanicsAtCaller Public Method Query<T, A: SqlValue>(sql: String, a: A): T[] Throws DatabaseError, ParseErrormethod #The rows
sql's one query reads as Ts, with its parameters bound to values as Execute's are. -
@PanicsAtCaller Public Method Query<T, A, B>(sql: String, a: A, b: B): T[] Throws DatabaseError, ParseErrormethod #The rows
sql's one query reads as Ts, with its parameters bound toathroughb, in order. -
@PanicsAtCaller Public Method Query<T, A, B, C>(sql: String, a: A, b: B, c: C): T[] Throws DatabaseError, ParseErrormethod #The rows
sql's one query reads as Ts, with its parameters bound toathroughc, in order. -
@PanicsAtCaller Public Method Query<T, A, B, C, D>(sql: String, a: A, b: B, c: C, d: D): T[] Throws DatabaseError, ParseErrormethod #The rows
sql's one query reads as Ts, with its parameters bound toathroughd, in order. -
@PanicsAtCaller Public Method Query<T, A, B, C, D, E>(sql: String, a: A, b: B, c: C, d: D, e: E): T[] Throws DatabaseError, ParseErrormethod #The rows
sql's one query reads as Ts, with its parameters bound toathroughe, in order. -
@PanicsAtCaller Public Method Query<T, A, B, C, D, E, F>(sql: String, a: A, b: B, c: C, d: D, e: E, f: F): T[] Throws DatabaseError, ParseErrormethod #The rows
sql's one query reads as Ts, with its parameters bound toathroughf, in order. -
@PanicsAtCaller Public Method Query<T, A, B, C, D, E, F, G>(sql: String, a: A, b: B, c: C, d: D, e: E, f: F, g: G): T[] Throws DatabaseError, ParseErrormethod #The rows
sql's one query reads as Ts, with its parameters bound toathroughg, in order. -
@PanicsAtCaller Public Method Query<T, A, B, C, D, E, F, G, H>(sql: String, a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H): T[] Throws DatabaseError, ParseErrormethod #The rows
sql's one query reads as Ts, with its parameters bound toathroughh, in order. -
@PanicsAtCaller Public Method Rows<A: SqlValue>(sql: String, a: A): Row[] Throws DatabaseErrormethod #The rows
sql's one query reads, with its parameters bound toa, in order. -
@PanicsAtCaller Public Method Rows<A, B>(sql: String, a: A, b: B): Row[] Throws DatabaseErrormethod #The rows
sql's one query reads, with its parameters bound toathroughb, in order. -
@PanicsAtCaller Public Method Rows<A, B, C>(sql: String, a: A, b: B, c: C): Row[] Throws DatabaseErrormethod #The rows
sql's one query reads, with its parameters bound toathroughc, in order. -
@PanicsAtCaller Public Method Rows<A, B, C, D>(sql: String, a: A, b: B, c: C, d: D): Row[] Throws DatabaseErrormethod #The rows
sql's one query reads, with its parameters bound toathroughd, in order. -
@PanicsAtCaller Public Method Rows<A, B, C, D, E>(sql: String, a: A, b: B, c: C, d: D, e: E): Row[] Throws DatabaseErrormethod #The rows
sql's one query reads, with its parameters bound toathroughe, in order. -
@PanicsAtCaller Public Method Rows<A, B, C, D, E, F>(sql: String, a: A, b: B, c: C, d: D, e: E, f: F): Row[] Throws DatabaseErrormethod #The rows
sql's one query reads, with its parameters bound toathroughf, in order. -
@PanicsAtCaller Public Method Rows<A, B, C, D, E, F, G>(sql: String, a: A, b: B, c: C, d: D, e: E, f: F, g: G): Row[] Throws DatabaseErrormethod #The rows
sql's one query reads, with its parameters bound toathroughg, in order. -
@PanicsAtCaller Public Method Rows<A, B, C, D, E, F, G, H>(sql: String, a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H): Row[] Throws DatabaseErrormethod #The rows
sql's one query reads, with its parameters bound toathroughh, in order. -
sql's one statement, prepared to run many times. Throws a DatabaseError of QUERY whensqlholds no statement or more than one, or one that doesn't prepare, like one that names a table the database hasn't got. -
A new Transaction, which keeps all of what this Database does until its Commit, or undoes it: see Transaction. One begun while another is open is a part of that one. The outermost is SQLite's IMMEDIATE, which waits for other connections to finish writing when it begins.
-
Brings the database up to date with
migrations, the SQL that makes each version of it from the one before: the first makes version 1 from an empty database, the second version 2, and so on. The database keeps its version, as PRAGMA user_version, so each migration runs once, in order, in a Transaction of its own with the version it makes, and one that fails leaves the database as the one before it left it, and throws. Throws a DatabaseError too when the database's version is past the last migration's, as a newer program's would be.
Statement
class
Public Class Statement
A statement prepared once, to run many times, its parameters bound to new values each time: what Database.Prepare makes. Its parameters are ?, ?NNN, :name, @name, and $name, numbered from 1 in order, as SQLite numbers them, and keep the values they're bound to until they're bound again, or Clear sets them to NULL. Closing its Database finalizes it, and using it after that panics, but for Parameters.
-
How many parameters it takes: the largest number one has.
-
Binds the parameter at
index, from 1, tovalue. Panics when it has none there. -
@PanicsAtCaller Public Method Bind<A: SqlValue>(name: String, value: A) Throws DatabaseErrormethod #Binds the parameter of
name, like ":id", tovalue. Panics when it has none of thatname. -
Sets each parameter to NULL.
-
Runs it, with its parameters as they're bound, and throws a DatabaseError when it fails.
-
Binds its parameters to values, in order, then runs it. Panics when it takes another number of them.
-
Binds its parameters to
athroughb, in order, then runs it. Panics when it takes another number of them. -
Binds its parameters to
athroughc, in order, then runs it. Panics when it takes another number of them. -
@PanicsAtCaller Public Method Execute<A, B, C, D>(a: A, b: B, c: C, d: D) Throws DatabaseErrormethod #Binds its parameters to
athroughd, in order, then runs it. Panics when it takes another number of them. -
@PanicsAtCaller Public Method Execute<A, B, C, D, E>(a: A, b: B, c: C, d: D, e: E) Throws DatabaseErrormethod #Binds its parameters to
athroughe, in order, then runs it. Panics when it takes another number of them. -
@PanicsAtCaller Public Method Execute<A, B, C, D, E, F>(a: A, b: B, c: C, d: D, e: E, f: F) Throws DatabaseErrormethod #Binds its parameters to
athroughf, in order, then runs it. Panics when it takes another number of them. -
@PanicsAtCaller Public Method Execute<A, B, C, D, E, F, G>(a: A, b: B, c: C, d: D, e: E, f: F, g: G) Throws DatabaseErrormethod #Binds its parameters to
athroughg, in order, then runs it. Panics when it takes another number of them. -
@PanicsAtCaller Public Method Execute<A, B, C, D, E, F, G, H>(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H) Throws DatabaseErrormethod #Binds its parameters to
athroughh, in order, then runs it. Panics when it takes another number of them. -
The rows it reads, with its parameters as they're bound.
-
The rows it reads, with its parameters as they're bound, each a T that
Load<T>makes of an Object of its columns by their names, each an integer, a Double, text, bytes, or Null, so a T's Fields of numbers, Bools as 0 or 1, Strings, UInt8[]s, Enums by their names, and T?s take them, and a Field no column has takes its default, or else its zero. Throws a ParseError for a row that doesn't make a T, whose Path starts with the row's index, as "[2].Age" does. -
@PanicsAtCaller Public Method Query<T, A: SqlValue>(a: A): T[] Throws DatabaseError, ParseErrormethod #Binds its parameters to values, in order, as Execute does, then gives the rows it reads as Ts, as
Query<T>()does. -
@PanicsAtCaller Public Method Query<T, A, B>(a: A, b: B): T[] Throws DatabaseError, ParseErrormethod #Binds its parameters to
athroughb, in order, then gives the rows it reads as Ts. -
@PanicsAtCaller Public Method Query<T, A, B, C>(a: A, b: B, c: C): T[] Throws DatabaseError, ParseErrormethod #Binds its parameters to
athroughc, in order, then gives the rows it reads as Ts. -
@PanicsAtCaller Public Method Query<T, A, B, C, D>(a: A, b: B, c: C, d: D): T[] Throws DatabaseError, ParseErrormethod #Binds its parameters to
athroughd, in order, then gives the rows it reads as Ts. -
@PanicsAtCaller Public Method Query<T, A, B, C, D, E>(a: A, b: B, c: C, d: D, e: E): T[] Throws DatabaseError, ParseErrormethod #Binds its parameters to
athroughe, in order, then gives the rows it reads as Ts. -
@PanicsAtCaller Public Method Query<T, A, B, C, D, E, F>(a: A, b: B, c: C, d: D, e: E, f: F): T[] Throws DatabaseError, ParseErrormethod #Binds its parameters to
athroughf, in order, then gives the rows it reads as Ts. -
@PanicsAtCaller Public Method Query<T, A, B, C, D, E, F, G>(a: A, b: B, c: C, d: D, e: E, f: F, g: G): T[] Throws DatabaseError, ParseErrormethod #Binds its parameters to
athroughg, in order, then gives the rows it reads as Ts. -
@PanicsAtCaller Public Method Query<T, A, B, C, D, E, F, G, H>(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H): T[] Throws DatabaseError, ParseErrormethod #Binds its parameters to
athroughh, in order, then gives the rows it reads as Ts. -
Binds its parameters to values, in order, as Execute does, then gives the rows it reads.
-
Binds its parameters to
athroughb, in order, then gives the rows it reads. -
Binds its parameters to
athroughc, in order, then gives the rows it reads. -
@PanicsAtCaller Public Method Rows<A, B, C, D>(a: A, b: B, c: C, d: D): Row[] Throws DatabaseErrormethod #Binds its parameters to
athroughd, in order, then gives the rows it reads. -
@PanicsAtCaller Public Method Rows<A, B, C, D, E>(a: A, b: B, c: C, d: D, e: E): Row[] Throws DatabaseErrormethod #Binds its parameters to
athroughe, in order, then gives the rows it reads. -
@PanicsAtCaller Public Method Rows<A, B, C, D, E, F>(a: A, b: B, c: C, d: D, e: E, f: F): Row[] Throws DatabaseErrormethod #Binds its parameters to
athroughf, in order, then gives the rows it reads. -
@PanicsAtCaller Public Method Rows<A, B, C, D, E, F, G>(a: A, b: B, c: C, d: D, e: E, f: F, g: G): Row[] Throws DatabaseErrormethod #Binds its parameters to
athroughg, in order, then gives the rows it reads. -
@PanicsAtCaller Public Method Rows<A, B, C, D, E, F, G, H>(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H): Row[] Throws DatabaseErrormethod #Binds its parameters to
athroughh, in order, then gives the rows it reads.
Transaction
class
Public Class Transaction
What Database.Begin gives. What the Database does from then on is kept when it commits, and undone when it rolls back, or when it's let go of without a Commit, as when an error leaves the code that holds it, so a transaction that fails leaves nothing. One begun while another was open is a part of that one: its Commit keeps what it did only as far as that one does, and that one's Rollback undoes it too.
-
Whether it's open: not committed or rolled back, by its own Methods, with the Transaction it's a part of, or by SQLite, as some errors do.
-
Keeps what it did. Throws a DatabaseError when SQLite can't, and it stays open, as when another connection is reading the database, or when it isn't open. Panics after its Commit or Rollback, or while a Transaction begun inside it is open.
-
Undoes what it did, and what each Transaction begun inside it did, or nothing when it isn't open. Panics after its Commit or Rollback.
Extends
Int8
extend
Extend Int8 Implements SqlValue
No doc comment.
Int16
extend
Extend Int16 Implements SqlValue
No doc comment.
Int32
extend
Extend Int32 Implements SqlValue
No doc comment.
Int64
extend
Extend Int64 Implements SqlValue
No doc comment.
UInt8
extend
Extend UInt8 Implements SqlValue
No doc comment.
UInt16
extend
Extend UInt16 Implements SqlValue
No doc comment.
UInt32
extend
Extend UInt32 Implements SqlValue
No doc comment.
UInt64
extend
Extend UInt64 Implements SqlValue
No doc comment.
Bool
extend
Extend Bool Implements SqlValue
No doc comment.
Float32
extend
Extend Float32 Implements SqlValue
No doc comment.
Float64
extend
Extend Float64 Implements SqlValue
No doc comment.
String
extend
Extend String Implements SqlValue
No doc comment.
UInt8[]
extend
Extend UInt8[] Implements SqlValue
No doc comment.
Report an issue with this page or with FutureBlitz on GitHub.