sql

Types from the Go package sql (a library PocketBase builds on), as JavaScript sees them: they turn up as values of PocketBase's types and of hook events.

sql.IsolationLevel

IsolationLevel is the transaction isolation level used in TxOptions.

Has everything Number has.

Member Type
string() (): string String returns the name of the transaction isolation level.

sql.DBStats

DBStats contains database statistics.

Member Type
maxOpenConnections number // Maximum number of open connections to the database.
openConnections number // The number of established connections both in use and idle. Pool Status
inUse number // The number of connections currently in use.
idle number // The number of idle connections.
waitCount number // The total number of connections waited for. Counters
waitDuration time.Duration // The total time blocked waiting for a new connection.
maxIdleClosed number // The total number of connections closed due to SetMaxIdleConns.
maxIdleTimeClosed number // The total number of connections closed due to SetConnMaxIdleTime.
maxLifetimeClosed number // The total number of connections closed due to SetConnMaxLifetime.

sql.Conn

Conn represents a single database connection rather than a pool of database connections. Prefer running queries from DB unless there is a specific need for a continuous single database connection.

A Conn must call Conn.close to return the connection to the database pool and may do so concurrently with a running query.

After a call to Conn.close, all operations on the connection fail with ErrConnDone.

Member Type
pingContext() (ctx: context.Context): void PingContext verifies the connection to the database is still alive.
execContext() (ctx: context.Context, query: string, ...args: any[]): Result ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
queryContext() (ctx: context.Context, query: string, ...args: any[]): (Rows) QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
queryRowContext() (ctx: context.Context, query: string, ...args: any[]): (Row) QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until the [*Row.Scan] method is called. If the query selects no rows, the [*Row.Scan] will return ErrNoRows. Otherwise, the [*Row.Scan] scans the first selected row and discards the rest.
prepareContext() (ctx: context.Context, query: string): (Stmt) PrepareContext creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's [*Stmt.Close] method when the statement is no longer needed.
raw() (f: (driverConn: any) => void): void Raw executes f exposing the underlying driver connection for the duration of f. The driverConn must not be used outside of f.
beginTx() (ctx: context.Context, opts: TxOptions): (Tx) BeginTx starts a transaction.
close() (): void Close returns the connection to the connection pool. All operations after a Close will return with ErrConnDone. Close is safe to call concurrently with other operations and will block until all other operations finish. It may be useful to first cancel any used context and then call close directly after.

sql.ColumnType

ColumnType contains the name and type of a column.

Member Type
name() (): string Name returns the name or alias of the column.
length() (): [number, boolean] Length returns the column type length for variable length column types such as text and binary field types. If the type length is unbounded the value will be math.maxInt64 (any database limits will still apply). If the column type is not variable length, such as an int, or if not supported by the driver ok is false.
decimalSize() (): [number, number, boolean] DecimalSize returns the scale and precision of a decimal type. If not applicable or if not supported ok is false.
scanType() (): any ScanType returns a Go type suitable for scanning into using Rows.scan. If a driver does not support this property ScanType will return the type of an empty interface.
nullable() (): [boolean, boolean] Nullable reports whether the column may be null. If a driver does not support this property ok will be false.
databaseTypeName() (): string DatabaseTypeName returns the database system name of the column type. If an empty string is returned, then the driver type name is not supported. Consult your driver documentation for a list of driver data types. ColumnType.length specifiers are not included. Common type names include "VARCHAR", "TEXT", "NVARCHAR", "DECIMAL", "BOOL", "INT", and "BIGINT".

sql.Row

Row is the result of calling DB.queryRow to select a single row.

Member Type
scan() (...dest: any[]): void Scan copies the columns from the matched row into the values pointed at by dest. See the documentation on Rows.scan for details. If more than one row matches the query, Scan uses the first row and discards the rest. If no row matches the query, Scan returns ErrNoRows.
err() (): void Err provides a way for wrapping packages to check for query errors without calling Row.scan. Err returns the error, if any, that was encountered while running the query. If this error is not nil, this error will also be returned from Row.scan.

sql.TxOptions

TxOptions holds the transaction options to be used in DB.beginTx.

Member Type
isolation IsolationLevel Isolation is the transaction isolation level. If zero, the driver or database's default level is used.
readOnly boolean

sql.NullString

NullString represents a string that may be null. NullString implements the Scanner interface so it can be used as a scan destination:

	var s NullString
	err := db.QueryRow("SELECT name FROM foo WHERE id=?", id).Scan(&s)
	...
	if s.Valid {
	   // use s.String
	} else {
	   // NULL value
	}
Member Type
string string
valid boolean // Valid is true if String is not NULL
scan() (value: any): void Scan implements the Scanner interface.
value() (): any Value implements the driver.valuer interface.

sql.DB

DB is a database handle representing a pool of zero or more underlying connections. It's safe for concurrent use by multiple goroutines.

The sql package creates and frees connections automatically; it also maintains a free pool of idle connections. If the database has a concept of per-connection state, such state can be reliably observed within a transaction (Tx) or connection (Conn). Once DB.begin is called, the returned Tx is bound to a single connection. Once Tx.commit or Tx.rollback is called on the transaction, that transaction's connection is returned to DB's idle connection pool. The pool size can be controlled with DB.setMaxIdleConns.

Member Type
pingContext() (ctx: context.Context): void PingContext verifies a connection to the database is still alive, establishing a connection if necessary.
ping() (): void Ping verifies a connection to the database is still alive, establishing a connection if necessary.
close() (): void Close closes the database and prevents new queries from starting. Close then waits for all queries that have started processing on the server to finish.
setMaxIdleConns() (n: number): void SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
setMaxOpenConns() (n: number): void SetMaxOpenConns sets the maximum number of open connections to the database.
setConnMaxLifetime() (d: time.Duration): void SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
setConnMaxIdleTime() (d: time.Duration): void SetConnMaxIdleTime sets the maximum amount of time a connection may be idle.
stats() (): DBStats Stats returns database statistics.
prepareContext() (ctx: context.Context, query: string): (Stmt) PrepareContext creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's [*Stmt.Close] method when the statement is no longer needed.
prepare() (query: string): (Stmt) Prepare creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's [*Stmt.Close] method when the statement is no longer needed.
execContext() (ctx: context.Context, query: string, ...args: any[]): Result ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
exec() (query: string, ...args: any[]): Result Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
queryContext() (ctx: context.Context, query: string, ...args: any[]): (Rows) QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
query() (query: string, ...args: any[]): (Rows) Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
queryRowContext() (ctx: context.Context, query: string, ...args: any[]): (Row) QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the [*Row.Scan] will return ErrNoRows. Otherwise, [*Row.Scan] scans the first selected row and discards the rest.
queryRow() (query: string, ...args: any[]): (Row) QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the [*Row.Scan] will return ErrNoRows. Otherwise, [*Row.Scan] scans the first selected row and discards the rest.
beginTx() (ctx: context.Context, opts: TxOptions): (Tx) BeginTx starts a transaction.
begin() (): (Tx) Begin starts a transaction. The default isolation level is dependent on the driver.
driver() (): any Driver returns the database's underlying driver.
conn() (ctx: context.Context): (Conn) Conn returns a single connection by either opening a new connection or returning an existing connection from the connection pool. Conn will block until either a connection is returned or ctx is canceled. Queries run on the same Conn will be run in the same database session.

sql.Tx

Tx is an in-progress database transaction.

A transaction must end with a call to Tx.commit or Tx.rollback.

After a call to Tx.commit or Tx.rollback, all operations on the transaction fail with ErrTxDone.

The statements prepared for a transaction by calling the transaction's Tx.prepare or Tx.stmt methods are closed by the call to Tx.commit or Tx.rollback.

Member Type
commit() (): void Commit commits the transaction.
rollback() (): void Rollback aborts the transaction.
prepareContext() (ctx: context.Context, query: string): (Stmt) PrepareContext creates a prepared statement for use within a transaction.
prepare() (query: string): (Stmt) Prepare creates a prepared statement for use within a transaction.
stmtContext() (ctx: context.Context, stmt: Stmt): (Stmt) StmtContext returns a transaction-specific prepared statement from an existing statement.
stmt() (stmt: Stmt): (Stmt) Stmt returns a transaction-specific prepared statement from an existing statement.
execContext() (ctx: context.Context, query: string, ...args: any[]): Result ExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE.
exec() (query: string, ...args: any[]): Result Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
queryContext() (ctx: context.Context, query: string, ...args: any[]): (Rows) QueryContext executes a query that returns rows, typically a SELECT.
query() (query: string, ...args: any[]): (Rows) Query executes a query that returns rows, typically a SELECT.
queryRowContext() (ctx: context.Context, query: string, ...args: any[]): (Row) QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the [*Row.Scan] will return ErrNoRows. Otherwise, the [*Row.Scan] scans the first selected row and discards the rest.
queryRow() (query: string, ...args: any[]): (Row) QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the [*Row.Scan] will return ErrNoRows. Otherwise, the [*Row.Scan] scans the first selected row and discards the rest.

sql.Stmt

Stmt is a prepared statement. A Stmt is safe for concurrent use by multiple goroutines.

If a Stmt is prepared on a Tx or Conn, it will be bound to a single underlying connection forever. If the Tx or Conn closes, the Stmt will become unusable and all operations will return an error. If a Stmt is prepared on a DB, it will remain usable for the lifetime of the DB. When the Stmt needs to execute on a new underlying connection, it will prepare itself on the new connection automatically.

Member Type
execContext() (ctx: context.Context, ...args: any[]): Result ExecContext executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
exec() (...args: any[]): Result Exec executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
queryContext() (ctx: context.Context, ...args: any[]): (Rows) QueryContext executes a prepared query statement with the given arguments and returns the query results as a [*Rows].
query() (...args: any[]): (Rows) Query executes a prepared query statement with the given arguments and returns the query results as a *Rows.
queryRowContext() (ctx: context.Context, ...args: any[]): (Row) QueryRowContext executes a prepared query statement with the given arguments. If an error occurs during the execution of the statement, that error will be returned by a call to Scan on the returned [*Row], which is always non-nil. If the query selects no rows, the [*Row.Scan] will return ErrNoRows. Otherwise, the [*Row.Scan] scans the first selected row and discards the rest.
queryRow() (...args: any[]): (Row) QueryRow executes a prepared query statement with the given arguments. If an error occurs during the execution of the statement, that error will be returned by a call to Scan on the returned [*Row], which is always non-nil. If the query selects no rows, the [*Row.Scan] will return ErrNoRows. Otherwise, the [*Row.Scan] scans the first selected row and discards the rest.
close() (): void Close closes the statement.

sql.Rows

Rows is the result of a query. Its cursor starts before the first row of the result set. Use Rows.next to advance from row to row.

Member Type
next() (): boolean Next prepares the next result row for reading with the Rows.scan method. It returns true on success, or false if there is no next result row or an error happened while preparing it. Rows.err should be consulted to distinguish between the two cases.
nextResultSet() (): boolean NextResultSet prepares the next result set for reading. It reports whether there is further result sets, or false if there is no further result set or if there is an error advancing to it. The Rows.err method should be consulted to distinguish between the two cases.
err() (): void Err returns the error, if any, that was encountered during iteration. Err may be called after an explicit or implicit Rows.close.
columns() (): Array<string> Columns returns the column names. Columns returns an error if the rows are closed.
columnTypes() (): Array<(ColumnType | undefined)> ColumnTypes returns column information such as column type, length, and nullable. Some information may not be available from some drivers.
scan() (...dest: any[]): void Scan copies the columns in the current row into the values pointed at by dest. The number of values in dest must be the same as the number of columns in Rows.
close() (): void Close closes the Rows, preventing further enumeration. If Rows.next is called and returns false and there are no further result sets, the Rows are closed automatically and it will suffice to check the result of Rows.err. Close is idempotent and does not affect the result of Rows.err.

sql.Result

A Result summarizes an executed SQL command.

Member Type
lastInsertId() (): number LastInsertId returns the integer generated by the database in response to a command. Typically this will be from an "auto increment" column when inserting a new row. Not all databases support this feature, and the syntax of such statements varies.
rowsAffected() (): number RowsAffected returns the number of rows affected by an update, insert, or delete. Not every database or database driver may support this.