Skip to content

SQL Driver (Knex) ​

The SQL driver implementation is based on Knex.js, a powerful SQL query builder. It supports all major SQL databases including PostgreSQL, MySQL, SQLite3, and SQL Server.

Installation ​

bash
npm install @objectql/driver-knex knex pg
# Replace 'pg' with 'mysql', 'sqlite3', or 'mssql' depending on your database.

Configuration ​

The KnexDriver constructor accepts the standard Knex configuration object.

typescript
import { KnexDriver } from '@objectql/driver-knex';

const driver = new KnexDriver({
  client: 'pg', // 'mysql', 'sqlite3', etc.
  connection: {
    host: '127.0.0.1',
    port: 5432,
    user: 'your_user',
    password: 'your_password',
    database: 'your_app_db'
  },
  // Optional: Connection pool settings
  pool: { min: 2, max: 10 }
});

SQLite Example ​

For local development or testing with SQLite:

typescript
const driver = new KnexDriver({
  client: 'sqlite3',
  connection: {
    filename: './local.db'
  },
  useNullAsDefault: true // Required for SQLite support
});

Schema Mapping ​

The driver automatically maps ObjectQL types to SQL column types:

ObjectQL TypeSQL TypeNotes
textVARCHAR(255)
textareaTEXT
booleanBOOLEANor TINYINT in MySQL
numberFLOAT / DECIMAL
dateDATE
datetimeTIMESTAMP
jsonJSONor TEXT if not supported

Released under the MIT License.