The SQL driver has been migrated to support the standard DriverInterface from @objectstack/spec while maintaining full backward compatibility with the existing Driver interface from @objectql/types.
The driver now exposes metadata for ObjectStack compatibility:
const driver = new SqlDriver(config);
console.log(driver.name); // 'SqlDriver'
console.log(driver.version); // '3.0.1'
console.log(driver.supports); // { transactions: true, joins: true, ... }New optional lifecycle methods for DriverInterface compatibility:
// Connect (no-op, connection established in constructor)
await driver.connect();
// Check connection health
const healthy = await driver.checkHealth(); // true/false
// Disconnect (existing method)
await driver.disconnect();The driver now supports the new QueryAST format from @objectstack/spec:
const query = {
fields: ['name', 'age'],
filters: [['age', '>', 18]],
sort: [['name', 'asc']],
limit: 10,
skip: 0,
aggregate: [{ func: 'sum', field: 'price', alias: 'total' }]
};const query = {
object: 'users',
fields: ['name', 'age'],
filters: [['age', '>', 18]],
sort: [{ field: 'name', order: 'asc' }],
top: 10, // Instead of 'limit'
skip: 0,
aggregations: [{ function: 'sum', field: 'price', alias: 'total' }]
};| Aspect | Legacy Format | QueryAST Format |
|---|---|---|
| Limit | limit: 10 |
top: 10 |
| Sort | [['field', 'dir']] |
[{field, order}] |
| Aggregations | aggregate: [{func, field, alias}] |
aggregations: [{function, field, alias}] |
The driver uses a normalization layer that automatically converts QueryAST format to the internal format:
private normalizeQuery(query: any): any {
// Converts 'top' → 'limit'
// Converts 'aggregations' → 'aggregate'
// Handles both sort formats
}This means:
- ✅ Existing code continues to work without changes
- ✅ New code can use QueryAST format
- ✅ Both formats work interchangeably
- ✅ No breaking changes
import { SqlDriver } from '@objectql/driver-sql';
const driver = new SqlDriver({
client: 'postgresql',
connection: { /* ... */ }
});
// Works as before
const results = await driver.find('users', {
filters: [['active', '=', true]],
sort: [['created_at', 'desc']],
limit: 20
});import { SqlDriver } from '@objectql/driver-sql';
const driver = new SqlDriver({
client: 'postgresql',
connection: { /* ... */ }
});
// New format
const results = await driver.find('users', {
filters: [['active', '=', true]],
sort: [{ field: 'created_at', order: 'desc' }],
top: 20
});import { ObjectQL } from '@objectql/core';
import { SqlDriver } from '@objectql/driver-sql';
const app = new ObjectQL({
datasources: {
default: new SqlDriver({ /* config */ })
}
});
await app.init();
// The kernel will use QueryAST format internally
const ctx = app.createContext({ userId: 'user123' });
const repo = ctx.object('users');
const users = await repo.find({ filters: [['active', '=', true]] });Comprehensive tests have been added in test/queryast.test.ts:
npm test -- queryast.test.tsTest coverage includes:
- Driver metadata exposure
- Lifecycle methods (connect, checkHealth, disconnect)
- QueryAST format with
topparameter - Object-based sort notation
- Aggregations with QueryAST format
- Backward compatibility with legacy format
- Mixed format support
package.json: Added@objectstack/spec@^0.2.0dependencysrc/index.ts:- Added driver metadata properties
- Added
normalizeQuery()method (~40 lines) - Added
connect()andcheckHealth()methods (~20 lines) - Updated
find(),count(),aggregate()to use normalization
test/queryast.test.ts: New comprehensive test suite (200+ lines)
- Added: ~260 lines (including tests and docs)
- Modified: ~10 lines (method signatures)
- Deleted: 0 lines
This migration establishes the pattern for migrating other drivers:
- ✅ SQL Driver (completed)
- 🔜 Memory Driver (recommended next - used for testing)
- 🔜 MongoDB Driver (NoSQL representative)
- 🔜 Other drivers (bulk migration)
100% backward compatible - all existing code using the SQL driver will continue to work without any changes. The QueryAST support is additive, not replacing.