pturso
Types
pub type Error {
DatabaseError(message: String)
DecodeError(errors: List(decode.DecodeError))
}
Constructors
-
DatabaseError(message: String) -
DecodeError(errors: List(decode.DecodeError))
pub type LogEntry {
LogEntry(sql: String, duration_ms: Int)
}
Constructors
-
LogEntry(sql: String, duration_ms: Int)
Parameter values for queries
pub type Param {
Null
Int(Int)
Float(Float)
String(String)
Blob(BitArray)
}
Constructors
-
Null -
Int(Int) -
Float(Float) -
String(String) -
Blob(BitArray)
Values
pub fn connect(
port: Port,
to db: String,
log_with logger_fn: fn(LogEntry) -> Nil,
) -> Connection
Creates a Connection object. Note that this doesn’t actually cause a real “connection” to be created. Actual DB connections are created lazily as queries come in.
The Connection object primarily exists as a way to make the API look similar to the sqlight library.
pub fn exec(
sql: String,
on conn: Connection,
) -> Result(Nil, Error)
sqlight-compatible exec function. Runs one or more SQL statements without prepared statements.
pub fn execute(
conn: Port,
db: String,
query: String,
params: List(Param),
) -> Result(Int, String)
Raw execute function for queries that do not return anything. Considered “low level” as it takes in Port and DB separately and is implemented in Erlang.
pub fn query(
sql: String,
on conn: Connection,
with params: List(Param),
expecting decoder: decode.Decoder(a),
) -> Result(List(a), Error)
sqlight-compatible query function.
pub fn run(
conn: Port,
db: String,
sql: String,
) -> Result(Nil, String)
Run one or more SQL statements without using prepared statements. Supports multiple statements separated by semicolons. Returns nothing on success.
pub fn select(
conn: Port,
db: String,
query: String,
params: List(Param),
) -> Result(List(dynamic.Dynamic), String)
Raw select function for queries that return results. Considered “low level” as it takes in Port and DB separately and is implemented in Erlang.
pub fn start() -> Result(Port, String)
Start the erso binary, automatically acquiring it if needed. Checks in order:
- ERSO environment variable
- cargo install (if cargo is available)
- GitHub release download
This function is idempotent; if you call it multiple times, you get the same Port back every time.
pub fn start_from_crates_io() -> Result(Port, String)
Start using erso installed via cargo install erso.
Calls cargo install erso if not already installed,
which builds the Rust binary from source.
pub fn start_from_github_release() -> Result(Port, String)
Start using pre-built erso binary downloaded from GitHub releases. Uses cached file on subsequent calls.
pub fn start_with_binary(
binary_path: String,
) -> Result(Port, String)
Start by passing in your own path to the erso binary.
If you don’t know what that is, you should consider using
one of the other start_* functions instead.