DbSession¶
Actor wrapper around Connection. Provides non-blocking behaviors that return Promises, enabling concurrent database access without blocking the caller's actor.
Each DbSession owns one Connection. Operations are serialized through the actor's mailbox — no concurrent access to the underlying ODBC handles.
Usage:
let db = DbSession(Dsn("DSN=mydb"))
let p = db.exec("CREATE TABLE t (id INTEGER)")
p.next[None]({(result: (RowCount | ExecError)) =>
match result
| let rc: RowCount => env.out.print("done")
| let e: ExecError => env.err.print(e.string())
end
})
Constructors¶
create¶
Parameters¶
- dsn: Dsn val
- opts: OdbcOptions val = reference
Returns¶
- DbSession tag^
Public Behaviours¶
exec¶
Execute DDL/DML and fulfill the promise with the result.
Parameters¶
query¶
Execute a SELECT and fulfill the promise with all rows. Fetches all rows into memory.
Parameters¶
begin¶
Begin a transaction.
Parameters¶
- promise: Promise[(TxBegun val | TxBeginError val)] tag
commit¶
Commit the current transaction.
Parameters¶
- promise: Promise[(TxCommitted val | TxCommitError val)] tag
rollback¶
Rollback the current transaction.
Parameters¶
- promise: Promise[(TxRolledBack val | TxRollbackError val)] tag
close¶
Close the underlying connection.