Skip to main content

DB

Description:

  A record that represents a database.

Column

Type: Field.

Description:

  Type definition for a database column. The boolean type is only used for representing the database NULL value with the boolean false value.

Signature:

type Column = integer | number | string | boolean

Row

Type: Field.

Description:

  Type definition for a database row.

Signature:

type Row = {Column}

SQL

Type: Field.

Description:

  Type definition for an SQL query. Can be SQL string or a pair of SQL string and an array of parameters.

Signature:

type SQL = string | {string, {Row}}

exist

Type: Function.

Description:

  Checks whether a table exists in the database.

Signature:

exist: function(self: DB, tableName: string, schema?: string): boolean

Parameters:

ParameterTypeDescription
tableNamestringThe name of the table to check.
schemastring[optional] The name of the schema to check in.

Returns:

Return TypeDescription
booleanWhether the table exists or not.

transaction

Type: Function.

Description:

  Executes a list of SQL statements as a single transaction.

Signature:

transaction: function(self: DB, sqls: {SQL}): boolean

Parameters:

ParameterTypeDescription
sqls{SQL}A list of SQL statements to execute.

Returns:

Return TypeDescription
booleanWhether the transaction was successful or not.

transactionAsync

Type: Function.

Description:

  Executes a list of SQL statements as a single transaction asynchronously.

Signature:

transactionAsync: function(self: DB, sqls: {SQL}): boolean

Parameters:

ParameterTypeDescription
sqls{SQL}A list of SQL statements to execute.

Returns:

Return TypeDescription
booleanWhether the transaction was successful or not.

query

Type: Function.

Description:

  Executes an SQL query and returns the results as a list of rows.

Signature:

query: function(
self: DB,
sql: string,
args: Row,
withColumn?: boolean --[[false]]
): {Row}

Parameters:

ParameterTypeDescription
sqlstringThe SQL statement to execute
argsRow[optional] A list of values to substitute into the SQL statement.
withColumnboolean[optional] Whether to include column names in the result (default false).

Returns:

Return TypeDescription
{Row}A list of rows returned by the query.

query

Type: Function.

Description:

  Executes an SQL query and returns the results as a list of rows.

Signature:

query: function(
self: DB,
sql: string,
withColumn?: boolean --[[false]]
): {Row} | nil

Parameters:

ParameterTypeDescription
sqlstringThe SQL statement to execute
withColumnboolean[optional] Whether to include column names in the result (default false).

Returns:

Return TypeDescription
{Row} | nilA list of rows returned by the query, or nil if the query failed.

insert

Type: Function.

Description:

  Inserts a row of data into a table within a transaction.

Signature:

insert: function(self: DB, tableName: string, values: {Row}): boolean

Parameters:

ParameterTypeDescription
tableNamestringThe name of the table to insert into.
valuesRowThe values to insert into the table.

Returns:

Return TypeDescription
booleanWhether the insertion was successful or not.

exec

Type: Function.

Description:

  Executes an SQL statement and returns the number of rows affected.

Signature:

exec: function(self: DB, sql: string): integer

Parameters:

ParameterTypeDescription
sqlstringThe SQL statement to execute.

Returns:

Return TypeDescription
integerThe number of rows affected by the statement, returns -1 if the statement failed.

exec

Type: Function.

Description:

  Executes an SQL statement and returns the number of rows affected.

Signature:

exec: function(self: DB, sql: string, values: Row): integer

Parameters:

ParameterTypeDescription
sqlstringThe SQL statement to execute.
valuesRowA list of values to substitute into the SQL statement.

Returns:

Return TypeDescription
integerThe number of rows affected by the statement, returns -1 if the statement failed.

exec

Type: Function.

Description:

  Executes an SQL statement with list of values and returns the number of rows affected within a transaction.

Signature:

exec: function(self: DB, sql: string, values: {Row}): integer

Parameters:

ParameterTypeDescription
sqlstringThe SQL statement to execute.
values{Row}A list of lists of values to substitute into the SQL statement.

Returns:

Return TypeDescription
integerthe number of rows affected by the statement, returns -1 if the statement failed.

insertAsync

Type: Function.

Description:

  Inserts a row of data into a table within a transaction asynchronously.

Signature:

insertAsync: function(self: DB, tableName: string, values: {Row}): boolean

Parameters:

ParameterTypeDescription
tableNamestringThe name of the table to insert into.
values{Row}The values to insert into the table.

Returns:

Return TypeDescription
booleanWhether the insert was successful or not.

insertAsync

Type: Function.

Description:

  Inserts data from an Excel file into a table within a transaction asynchronously.

Signature:

insertAsync: function(self: DB, tableSheets: {string}, excelFile: string, startRow: integer): boolean

Parameters:

ParameterTypeDescription
tableSheets{string}the names of the tables to insert into.
excelFilestringThe path to the Excel file containing the data.
startRowintegerThe row number to start inserting data from. The row number start with 1.

Returns:

Return TypeDescription
booleanWhether the insert was successful or not.

insertAsync

Type: Function.

Description:

  Inserts data from an Excel file into a table within a transaction asynchronously.

Signature:

insertAsync: function(self: DB, tableSheets: {{string, string}}, excelFile: string, startRow: integer): boolean

Parameters:

ParameterTypeDescription
tableSheets{{string, string}}A list of table names and corresponding sheet names to insert into.
excelFilestringThe path to the Excel file containing the data.
startRowintegerThe row number to start inserting data from. The row number start with 1.

Returns:

Return TypeDescription
booleanWhether the insert was successful or not.

queryAsync

Type: Function.

Description:

  Executes an SQL query asynchronously and returns the results as a list of rows.

Signature:

queryAsync: function(
self: DB,
sql: string,
args: Row,
withColumn?: boolean --[[false]]
): {Row} | nil

Parameters:

ParameterTypeDescription
sqlstringThe SQL statement to execute.
argsRow[optional] A list of values to substitute into the SQL statement.
withColumnboolean[optional] Whether to include column names in the result (default false).

Returns:

Return TypeDescription
{Row} | nilA list of rows returned by the query, or nil if the query failed.

queryAsync

Type: Function.

Description:

  Executes an SQL query asynchronously and returns the results as a list of rows.

Signature:

queryAsync: function(
self: DB,
sql: string,
withColumn?: boolean --[[false]]
): {Row} | nil

Parameters:

ParameterTypeDescription
sqlstringThe SQL statement to execute.
withColumnboolean[optional] Whether to include column names in the result (default false).

Returns:

Return TypeDescription
{Row} | nilA list of rows returned by the query, or nil if the query failed.

execAsync

Type: Function.

Description:

  Executes an SQL statement with a list of values within a transaction asynchronously and returns the number of rows affected.

Signature:

execAsync: function(self: DB, sql: string, values: {Row}): integer

Parameters:

ParameterTypeDescription
sqlstringThe SQL statement to execute.
values{Row}A list of values to substitute into the SQL statement.

Returns:

Return TypeDescription
integerThe number of rows affected by the statement, returns -1 if the statement failed.

execAsync

Type: Function.

Description:

  Executes an SQL statement asynchronously and returns the number of rows affected.

Signature:

execAsync: function(self: DB, sql: string): integer

Parameters:

ParameterTypeDescription
sqlstringThe SQL statement to execute.

Returns:

Return TypeDescription
integerthe number of rows affected by the statement, returns -1 if the statement failed.