Module

Node.SQLite

Package
purescript-node-sqlite
Repository
m-rinaldi/purescript-node-sqlite

#DB Source

data DB

An opaque handle to an open SQLite database.

#SQLiteError Source

data SQLiteError

Errors that can occur when running a query.

  • SQLite'Exception: an error thrown by the underlying SQLite engine.
  • SQLite'DecodeError: the rows returned by SQLite could not be decoded into the expected PureScript type.

Constructors

Instances

#Options Source

type Options = { allowExtension :: Boolean, allowUnknownNamedParameters :: Boolean, defensive :: Boolean, enableDoubleQuotedStringLiterals :: Boolean, enableForeignKeyConstraints :: Boolean, readOnly :: Boolean, timeout :: Int }

Options for open.

  • readOnly: If true, the database is opened in read-only mode. If the database does not exist, opening it will fail.
  • enableForeignKeyConstraints: If true, foreign key constraints are enabled. This is recommended but can be disabled for compatibility with legacy database schemas. The enforcement of foreign key constraints can be enabled and disabled after opening the database using PRAGMA foreign_keys.
  • enableDoubleQuotedStringLiterals: If true, SQLite will accept double-quoted string literals. This is not recommended but can be enabled for compatibility with legacy database schemas.
  • allowExtension: If true, the loadExtension SQL function and the loadExtension() method are enabled.
  • timeout The busy timeout in milliseconds. This is the maximum amount of time that SQLite will wait for a database lock to be released before returning an error.
  • allowUnknownNamedParameters: If true, unknown named parameters are ignored when binding. If false, an exception is thrown for unknown named parameters.
  • defensive: If true, enables the defensive flag. When the defensive flag is enabled, language features that allow ordinary SQL to deliberately corrupt the database file are disabled.

#RunResult Source

type RunResult = { changes :: Int, lastInsertRowid :: Number }

Result returned by run.

  • changes: number of rows affected by the statement.
  • lastInsertRowid: rowid of the last INSERT on this connection; unchanged (not reset) for non-INSERT statements.

#Statement Source

data Statement :: Row Type -> Row Type -> Typedata Statement t0 t1

An opaque handle to a compiled prepared statement.

#all Source

all :: forall @r rl m inputR. RowToList r rl => DecodeSQL (Array (Record r)) => Encode (Record inputR) => MonadEffect m => Statement inputR r -> Record inputR -> ExceptT SQLiteError m (Array (Record r))

all runs a SELECT (or any row-returning statement, e.g. a RETURNING clause) and returns every matching row as an array. Use it when you expect zero or more rows.

#close Source

close :: DB -> Effect (Either Error Unit)

Closes the database connection.

#defaultOptions Source

defaultOptions :: Options

Default options for open. Foreign keys are enabled and the defensive flag is on; everything else is disabled and the busy timeout is 0.

#exec Source

exec :: DB -> String -> Effect (Either Error Unit)

exec takes a raw SQL string and executes it directly (no preparation, no parameters), and returns nothing.

Good for multi-statement scripts like schema migrations.

#get Source

get :: forall @r rl m iR. RowToList r rl => DecodeSQL (Maybe (Record r)) => Encode (Record iR) => MonadEffect m => Statement iR r -> Record iR -> ExceptT SQLiteError m (Maybe (Record r))

get runs a SELECT (or any row-returning statement) and returns the first matching row, or Nothing if no rows matched. Use it for lookups that yield at most one row (e.g. a primary-key or LIMIT 1 query).

#open Source

open :: String -> Options -> Effect (Either Error DB)

Opens a database file at the given path with the provided options.

#openInMemory Source

openInMemory :: Options -> Effect (Either Error DB)

Opens a temporary in-memory database. The database is gone when closed.

#prepare Source

prepare :: forall (inputR :: Row Type) (outputR :: Row Type). DB -> Proxy inputR -> String -> Proxy outputR -> Effect (Either Error (Statement inputR outputR))

Compiles a SQL string into a prepared statement.

Statements are always tied to a specific DB connection.

#prepare' Source

prepare' :: forall outputR. DB -> String -> Proxy outputR -> Effect (Either Error (Statement () outputR))

#prepare_ Source

#run Source

run :: forall (iR :: Row Type). Encode (Record iR) => Statement iR () -> Record iR -> Effect (Either Error RunResult)

runs a prepared statement.

It does not return rows, used for INSERT, UPDATE and DELETE.