-
Notifications
You must be signed in to change notification settings - Fork 0
libsqlTypes
Every function in this library returns a libsqlResult<T, R>
type.
libsqlResult<T, R>
is either:
{
isOk: true,
val: T
}
or:
{
isOk: false,
err: R
}
For example, the function await
libsqlExecute
returns libsqlResult<libsqlStatementResOkData, libsqlStreamResErrData|libsqlPipelineResErr>
, which is either:
{
isOk: true,
val: libsqlStatementResOkData
}
or:
{
isOk: false,
err: libsqlStreamResErrData|libsqlPipelineResErr
}
- No need of ugly try { } catch { }.
- Elegant error handling:
//you can do something like
const res = await libsqlExecute(conf, {sql: "SELECT * FROM mad_cats;"});
if (res.isOk) {
//now res.val is guaranteed by typescript [js users, sorry]
console.log(res.val.rows); //the rows returned
console.log(res.val.affected_row_count) //affected rows
//...
} else {
//now res.err is guaranteed by typescript
console.log(res.err.message); //error message
doSomething(res.err.code) //do something with the error code
//...
}
Reference: libsqlExecute
, libsqlStatementResOkData
, libsqlStreamResErrData
, libsqlPipelineResErr
The connection config to your libsql-server (DB)
{
db_url: string,
authToken?: string
}
{
baton: string | null,
requests: Array<libsqlCloseStreamReq|libsqlExecuteStreamReq|libsqlBatchStreamReq>
}
Reference: libsqlCloseStreamReq
, libsqlExecuteStreamReq
, libsqlBatchStreamReq
{
baton: string | null,
base_url: string | null,
results: Array<libsqlStreamResOk|libsqlStreamResErr>
}
Reference: libsqlStreamResOk
, libsqlStreamResErr
Returned when something went seriously wrong with the server.
string |
{
error: string
}
{
type: "close",
}
{
type: "execute",
stmt: libsqlSQLStatement
}
Reference: libsqlSQLStatement
{
type: "batch",
batch: {
steps: Array<libsqlBatchReqStep>,
}
}
Reference: libsqlBatchReqStep
{
type: "ok",
response: libsqlCloseStreamResOk|libsqlExecuteStreamResOk|libsqlBatchStreamResOk
}
Reference: libsqlCloseStreamResOk
, libsqlExecuteStreamResOk
, libsqlBatchStreamResOk
{
type: "error",
error: libsqlStreamResErrData
}
Reference: libsqlStreamResErrData
An SQL statement, formatted for the server.
{
sql: string,
args?: Array<libsqlSQLValue>,
named_args?: Array<{
name: string,
value: libsqlSQLValue,
}>,
want_rows?: boolean,
}
Reference: libsqlSQLValue
A step in a batch request.
{
condition?: libsqlBatchReqStepExecCond | null,
stmt: libsqlSQLStatement,
}
A batch step is executed only when condition
is either null
or evaluates to true
.
Reference: libsqlBatchReqStepExecCond
, libsqlSQLStatement
{
type: "close",
}
{
type: "execute",
result: libsqlStatementResOkData
}
Reference: libsqlStatementResOkData
{
type: "batch",
result: libsqlBatchStreamResOkData,
}
Reference: libsqlBatchStreamResOkData
Returned when something went wrong with the server.
{
message: string,
code?: string | null
}
Types of values returned by the server. You are responsible for processing them appropriately. Or you could use libsql-stateless-easy
instead of this library.
{ type: "null" } |
{ type: "integer", value: string } |
{ type: "float", value: number } |
{ type: "text", value: string } |
{ type: "blob", base64: string };
Each of these evaluates to either true
or false
.
{ type: "ok", step: number } | //uint32: 0-based index in the steps array
{ type: "error", step: number } | //uint32: 0-based index in the steps array
{ type: "not", cond: libsqlBatchReqStepExecCond } |
{ type: "and", conds: Array<libsqlBatchReqStepExecCond> } |
{ type: "or", conds: Array<libsqlBatchReqStepExecCond> } |
{ type: "is_autocommit" };
-
ok
evaluates to true if thestep
(referenced by its 0-based index) was executed successfully. If the statement was skipped, this condition evaluates to false. -
error
evaluates to true if thestep
(referenced by its 0-based index) has produced an error. If the statement was skipped, this condition evaluates to false. -
not
evaluatescond
and returns the logical negative. -
and
evaluatesconds
and returns the logical conjunction of them. -
or
evaluatesconds
and returns the logical disjunction of them. -
is_autocommit
evaluates to true if the stream is currently in the autocommit state (not inside an explicit transaction) Reference:libsqlBatchReqStepExecCond
The data returned by the server on execution of an SQL statement.
{
cols: Array<libsqlSQLColumn>,
rows: Array<Array<libsqlSQLValue>>,
affected_row_count: number, //uint32
last_insert_rowid: string | null
}
Reference: libsqlSQLColumn
, libsqlSQLValue
The data returned by the server on execution of a batch of SQL statement.
{
step_results: Array<libsqlStatementResOkData | null>,
step_errors: Array<libsqlStreamResErrData | null>
}
Reference: libsqlStatementResOkData
, libsqlStreamResErrData
{
name: string | null,
decltype: string | null
}