based
Types
pub type DB(a, c) {
DB(conn: c, execute: Adapter(a, c))
}
Constructors
-
DB(conn: c, execute: Adapter(a, c))
pub type Query(a) {
Query(
sql: String,
args: List(Value),
decoder: Option(dynamic.Decoder(a)),
)
}
Constructors
-
Query( sql: String, args: List(Value), decoder: Option(dynamic.Decoder(a)), )
pub type Returned(a) {
Returned(count: Int, rows: List(a))
}
Constructors
-
Returned(count: Int, rows: List(a))
Callers will interact with these Value types when building queries. Their chosen backend is responsible for converting these Value types to the appropriate type.
pub type Value {
String(String)
Int(Int)
Float(Float)
Bool(Bool)
Null
}
Constructors
-
String(String)
-
Int(Int)
-
Float(Float)
-
Bool(Bool)
-
Null
Defines a valid with_connection
function
pub type WithConnection(a, b, c) =
fn(b, fn(DB(a, c)) -> Result(Returned(a), Nil)) ->
Result(Returned(a), Nil)
Functions
pub fn all(
query: Query(a),
db: DB(a, b),
) -> Result(Returned(a), Nil)
The same as exec
, but explicitly tells a reader that all queried rows are expected.
pub fn exec(
query: Query(a),
db: DB(a, b),
) -> Result(Returned(a), Nil)
Performs the query against the provided db
pub fn register(
with_connection: fn(a, fn(DB(b, c)) -> Result(Returned(b), Nil)) ->
Result(Returned(b), Nil),
b: a,
callback: fn(DB(b, c)) -> Result(Returned(b), Nil),
) -> Result(Returned(b), Nil)
Expects a with_connection
function and its first required argument. For a library
implementing a with_connection
function, the required argument will likely be its
configuration data.
In the case of based/testing.with_connection
, the required argument is the expected
return data.
pub fn with_decoder(
query: Query(a),
decoder: fn(Dynamic) -> Result(a, List(DecodeError)),
) -> Query(a)