Overview
EverShop provides a powerful query builder API for PostgreSQL, built on top of thepg driver. The API offers a fluent interface for constructing and executing SQL queries with type safety and connection management.
Database Connection
pool
Global PostgreSQL connection pool instance.packages/evershop/src/lib/postgres/connection.ts:58
Configuration
Connection settings are configured via environment variables:SSL Configuration
For SSL connections:getConnection()
Get a dedicated connection from the pool for transactions.packages/evershop/src/lib/postgres/connection.ts:65
Query Builder
select()
Create a SELECT query.packages/postgres-query-builder/src/index.ts:1168
Methods
insert()
Create an INSERT query.packages/postgres-query-builder/src/index.ts:1183
Methods
update()
Create an UPDATE query.packages/postgres-query-builder/src/index.ts:1198
Methods
del()
Create a DELETE query.packages/postgres-query-builder/src/index.ts:1202
insertOnUpdate()
Create an INSERT … ON CONFLICT DO UPDATE query (upsert).packages/postgres-query-builder/src/index.ts:1187
Transaction Management
startTransaction()
Begin a database transaction.packages/postgres-query-builder/src/index.ts:1116
commit()
Commit a transaction and release the connection.packages/postgres-query-builder/src/index.ts:1122
rollback()
Rollback a transaction and release the connection.packages/postgres-query-builder/src/index.ts:1129
Utility Functions
sql()
Mark a value as raw SQL (not escaped).packages/postgres-query-builder/src/index.ts:1153
value()
Explicitly mark a value as a bound parameter (default behavior).packages/postgres-query-builder/src/index.ts:1160
execute()
Execute raw SQL.packages/postgres-query-builder/src/index.ts:1146
Operators
Supported operators in WHERE clauses:=- Equal!=- Not equal>- Greater than>=- Greater than or equal<- Less than<=- Less than or equalLIKE- Pattern matchingIN- In arrayNOT IN- Not in arrayIS NULL- Is nullIS NOT NULL- Is not null
Best Practices
Always Use the Pool for Simple Queries
Use
pool for single queries. Reserve getConnection() for transactions.Use Parameterized Queries
The query builder automatically parameterizes values to prevent SQL injection.
Use Transactions for Multi-Step Operations
Group related INSERT/UPDATE/DELETE operations in transactions for data consistency.