Query Builder

Stackpress provides a super lightweight generic typed SQL query builder, SQL dialects and sql composite engine. In order to use the SQL query builder you need to install the following packages depending on the SQL engine you are trying to use.
pgsql
pglite
mysql
sqlite
Copy
Once you have installed the required packages, the following examples show how to setup the database connection would look like depending on the SQL engine you are trying to use.
pgsql
pglite
mysql
sqlite
Copy
NOTE: It's recommended to setup the database as described in the Toolkit Setup tutorial.
In a plugin you can access the database connection using the method like the following.
Copy
In a route or event you can access the database connection using the method like the following.
Copy

connection

Returns the SQL connection. This is a secondary wrapper that provides access to the resource designed around a common interface.
Copy

Example

Copy

dialect

Returns the SQL dialect. A dialect is a set of functions that are used to format the SQL queries depending on the SQL database engine. The following is the interface of an SQL dialect.
Copy

Example

Copy

alter()

Return an alter table query builder. See AlterBuilder.

Usage

Copy

Example

Copy

create()

Return a create table query builder. See CreateBuilder.

Usage

Copy

Example

Copy

delete()

Return a delete query builder. See DeleteBuilder.

Usage

Copy

Example

Copy

diff()

Compares two create builders and generates an alter builder.
NOTE: This does not compare table names

Usage

Copy

Example

Copy

drop()

Drops a table.

Usage

Copy

Example

Copy

insert()

Return an insert query builder. See InsertBuilder.

Usage

Copy

Example

Copy

query()

Query the database. Should return just the expected results, because the raw results depends on the native database engine connection.
NOTE: Any code that uses this library should not care about the kind of database.

Usage

Copy
Copy

Example

Copy
Copy

rename()

Renames a table.

Usage

Copy

Example

Copy

select()

Return a select query builder. See SelectBuilder.

Usage

Copy

Example

Copy

sql()

Template string query builder.

Usage

Copy

Example

Copy

transaction()

Common pattern to invoke a transaction. The callback function accepts a Connection interface argument.

Usage

Copy

Example

Copy

truncate()

Truncate a table.

Usage

Copy

Example

Copy

update()

Return an update query builder. See UpdateBuilder.

Usage

Copy

Example

Copy