Back to Pocketbase

Interface DB

static/jsvm/interfaces/dbx.DB.html

latest17.0 KB
Original Source

Interface DB

DB enhances sql.DB by providing a set of DB-agnostic query building methods. DB allows easier query building and population of data into Go variables.

Hierarchy

Index

Methods

addColumnaddForeignKeyaddPrimaryKeyalterColumnbeginbeginTxcloneclosecontextcreateIndexcreateTablecreateUniqueIndexdbdeletedriverNamedropColumndropForeignKeydropIndexdropPrimaryKeydropTablegeneratePlaceholderinsertmodelnewQueryqueryBuilderquotequoteColumnNamequoteSimpleColumnNamequoteSimpleTableNamequoteTableNamerenameColumnrenameTableselecttransactionaltransactionalContexttruncateTableupdateupsertwithContextwrap

Properties

execLogFuncfieldMapperlogFuncperfFuncqueryLogFunctableMapper

Methods

addColumn

  • addColumn(table, col, typ): Query

AddColumn creates a Query that can be used to add a column to a table.

Parameters

table: string
col: string
typ: string

Returns Query

addForeignKey

  • addForeignKey(table, name, cols, refCols, refTable, ...options): Query

AddForeignKey creates a Query that can be used to add a foreign key constraint to a table. The length of cols and refCols must be the same as they refer to the primary and referential columns. The optional "options" parameters will be appended to the SQL statement. They can be used to specify options such as "ON DELETE CASCADE".

Parameters

table: string
name: string
cols: string[]
refCols: string[]
refTable: string
Rest ...options: string[]

Returns Query

addPrimaryKey

  • addPrimaryKey(table, name, ...cols): Query

AddPrimaryKey creates a Query that can be used to specify primary key(s) for a table. The "name" parameter specifies the name of the primary key constraint.

Parameters

table: string
name: string
Rest ...cols: string[]

Returns Query

alterColumn

  • alterColumn(table, col, typ): Query

AlterColumn creates a Query that can be used to change the definition of a table column.

Parameters

table: string
col: string
typ: string

Returns Query

begin

Begin starts a transaction.

Returns dbx.Tx

beginTx

  • beginTx(ctx, opts): dbx.Tx

BeginTx starts a transaction with the given context and transaction options.

Parameters

ctx: context.Context
opts: TxOptions

Returns dbx.Tx

clone

Clone makes a shallow copy of DB.

Returns dbx.DB

close

  • close(): void

Close closes the database, releasing any open resources. It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.

Returns void

context

Context returns the context associated with the DB instance. It returns nil if no context is associated.

Returns context.Context

createIndex

  • createIndex(table, name, ...cols): Query

CreateIndex creates a Query that can be used to create an index for a table.

Parameters

table: string
name: string
Rest ...cols: string[]

Returns Query

createTable

  • createTable(table, cols, ...options): Query

CreateTable creates a Query that represents a CREATE TABLE SQL statement. The keys of cols are the column names, while the values of cols are the corresponding column types. The optional "options" parameters will be appended to the generated SQL statement.

Parameters

table: string
cols: _TygojaDict
Rest ...options: string[]

Returns Query

createUniqueIndex

  • createUniqueIndex(table, name, ...cols): Query

CreateUniqueIndex creates a Query that can be used to create a unique index for a table.

Parameters

table: string
name: string
Rest ...cols: string[]

Returns Query

db

DB returns the sql.DB instance encapsulated by dbx.DB.

Returns sql.DB

delete

  • delete(table, where): Query

Delete creates a Query that represents a DELETE SQL statement. If the "where" expression is nil, the DELETE SQL statement will have no WHERE clause (be careful in this case as the SQL statement will delete ALL rows in the table).

Parameters

table: string
where: Expression

Returns Query

driverName

  • driverName(): string

DriverName returns the name of the DB driver.

Returns string

dropColumn

  • dropColumn(table, col): Query

DropColumn creates a Query that can be used to drop a column from a table.

Parameters

table: string
col: string

Returns Query

dropForeignKey

  • dropForeignKey(table, name): Query

DropForeignKey creates a Query that can be used to remove the named foreign key constraint from a table.

Parameters

table: string
name: string

Returns Query

dropIndex

  • dropIndex(table, name): Query

DropIndex creates a Query that can be used to remove the named index from a table.

Parameters

table: string
name: string

Returns Query

dropPrimaryKey

  • dropPrimaryKey(table, name): Query

DropPrimaryKey creates a Query that can be used to remove the named primary key constraint from a table.

Parameters

table: string
name: string

Returns Query

dropTable

  • dropTable(table): Query

DropTable creates a Query that can be used to drop a table.

Parameters

table: string

Returns Query

generatePlaceholder

  • generatePlaceholder(_arg0): string

GeneratePlaceholder generates an anonymous parameter placeholder with the given parameter ID.

Parameters

_arg0: number

Returns string

insert

  • insert(table, cols): Query

Insert creates a Query that represents an INSERT SQL statement. The keys of cols are the column names, while the values of cols are the corresponding column values to be inserted.

Parameters

table: string
cols: Params

Returns Query

model

ModelQuery returns a new ModelQuery object that can be used to perform model insertion, update, and deletion. The parameter to this method should be a pointer to the model struct that needs to be inserted, updated, or deleted.

Parameters

_arg0: {}

Returns ModelQuery

newQuery

NewQuery creates a new Query object with the given SQL statement. The SQL statement may contain parameter placeholders which can be bound with actual parameter values before the statement is executed.

Parameters

_arg0: string

Returns Query

queryBuilder

QueryBuilder returns the query builder supporting the current DB.

Returns QueryBuilder

quote

  • quote(_arg0): string

Quote quotes a string so that it can be embedded in a SQL statement as a string value.

Parameters

_arg0: string

Returns string

quoteColumnName

  • quoteColumnName(s): string

QuoteColumnName quotes the given column name appropriately. If the table name contains table name prefix, it will be handled accordingly. This method will do nothing if the column name is already quoted or if it contains parenthesis.

Parameters

s: string

Returns string

quoteSimpleColumnName

  • quoteSimpleColumnName(_arg0): string

QuoteSimpleColumnName quotes a simple column name. A simple column name does not contain any table prefix.

Parameters

_arg0: string

Returns string

quoteSimpleTableName

  • quoteSimpleTableName(_arg0): string

QuoteSimpleTableName quotes a simple table name. A simple table name does not contain any schema prefix.

Parameters

_arg0: string

Returns string

quoteTableName

  • quoteTableName(s): string

QuoteTableName quotes the given table name appropriately. If the table name contains DB schema prefix, it will be handled accordingly. This method will do nothing if the table name is already quoted or if it contains parenthesis.

Parameters

s: string

Returns string

renameColumn

  • renameColumn(table, oldName, newName): Query

RenameColumn creates a Query that can be used to rename a column in a table.

Parameters

table: string
oldName: string
newName: string

Returns Query

renameTable

  • renameTable(oldName, newName): Query

RenameTable creates a Query that can be used to rename a table.

Parameters

oldName: string
newName: string

Returns Query

select

Select returns a new SelectQuery object that can be used to build a SELECT statement. The parameters to this method should be the list column names to be selected. A column name may have an optional alias name. For example, Select("id", "my_name AS name").

Parameters

Rest ..._arg0: string[]

Returns SelectQuery

transactional

  • transactional(f): void

Transactional starts a transaction and executes the given function. If the function returns an error, the transaction will be rolled back. Otherwise, the transaction will be committed.

Parameters

f: ((_arg0) => void)
- 
  - (\_arg0): void
  - 

Parameters

    - 
_arg0: dbx.Tx

Returns void

Returns void

transactionalContext

  • transactionalContext(ctx, opts, f): void

TransactionalContext starts a transaction and executes the given function with the given context and transaction options. If the function returns an error, the transaction will be rolled back. Otherwise, the transaction will be committed.

Parameters

ctx: context.Context
opts: TxOptions
f: ((_arg0) => void)
- 
  - (\_arg0): void
  - 

Parameters

    - 
_arg0: dbx.Tx

Returns void

Returns void

truncateTable

  • truncateTable(table): Query

TruncateTable creates a Query that can be used to truncate a table.

Parameters

table: string

Returns Query

update

  • update(table, cols, where): Query

Update creates a Query that represents an UPDATE SQL statement. The keys of cols are the column names, while the values of cols are the corresponding new column values. If the "where" expression is nil, the UPDATE SQL statement will have no WHERE clause (be careful in this case as the SQL statement will update ALL rows in the table).

Parameters

table: string
cols: Params
where: Expression

Returns Query

upsert

  • upsert(table, cols, ...constraints): Query

Upsert creates a Query that represents an UPSERT SQL statement. Upsert inserts a row into the table if the primary key or unique index is not found. Otherwise it will update the row with the new values. The keys of cols are the column names, while the values of cols are the corresponding column values to be inserted.

Parameters

table: string
cols: Params
Rest ...constraints: string[]

Returns Query

withContext

  • withContext(ctx): dbx.DB

WithContext returns a new instance of DB associated with the given context.

Parameters

ctx: context.Context

Returns dbx.DB

wrap

Wrap encapsulates an existing transaction.

Parameters

sqlTx: sql.Tx

Returns dbx.Tx

Properties

execLogFunc

execLogFunc: ExecLogFunc

ExecLogFunc is called each time when a SQL statement is executed.

fieldMapper

fieldMapper: FieldMapFunc

FieldMapper maps struct fields to DB columns. Defaults to DefaultFieldMapFunc.

logFunc

logFunc: LogFunc

LogFunc logs the SQL statements being executed. Defaults to nil, meaning no logging.

perfFunc

perfFunc: PerfFunc

PerfFunc logs the SQL execution time. Defaults to nil, meaning no performance profiling. Deprecated: Please use QueryLogFunc and ExecLogFunc instead.

queryLogFunc

queryLogFunc: QueryLogFunc

QueryLogFunc is called each time when performing a SQL query that returns data.

tableMapper

tableMapper: TableMapFunc

TableMapper maps structs to table names. Defaults to GetTableName.

Settings

Member Visibility

  • Inherited

Theme

OSLightDark

On This Page

Generated using TypeDoc