Skip to content

DbSession

[Source]

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
})

actor tag DbSession

Constructors

create

[Source]

new tag create(
  dsn: Dsn val,
  opts: OdbcOptions val = reference)
: DbSession tag^

Parameters

Returns


Public Behaviours

exec

[Source]

Execute DDL/DML and fulfill the promise with the result.

be exec(
  sql: String val,
  promise: Promise[(RowCount | ExecError val)] tag)

Parameters


query

[Source]

Execute a SELECT and fulfill the promise with all rows. Fetches all rows into memory.

be query(
  sql: String val,
  promise: Promise[(Array[Row val] val | ExecError val)] tag)

Parameters


begin

[Source]

Begin a transaction.

be begin(
  promise: Promise[(TxBegun val | TxBeginError val)] tag)

Parameters


commit

[Source]

Commit the current transaction.

be commit(
  promise: Promise[(TxCommitted val | TxCommitError val)] tag)

Parameters


rollback

[Source]

Rollback the current transaction.

be rollback(
  promise: Promise[(TxRolledBack val | TxRollbackError val)] tag)

Parameters


close

[Source]

Close the underlying connection.

be close()