Query Reference
Complete reference for the Warehouse query language syntax.
Query Structure
interface IWarehouseQuery {
operation: 'select' | 'insert' | 'update' | 'delete' | 'upsert';
from: IDataSource;
fields?: string[];
join?: IJoinClause[];
where?: IWhereClause;
orderBy?: IOrderBy[];
groupBy?: string[];
having?: IWhereClause;
limit?: number;
offset?: number;
data?: Record<string, any> | Record<string, any>[];
returning?: boolean;
}
Data Source
Specifies which database, graph, or vector store to query:
interface IDataSource {
type: 'database' | 'graph' | 'vector';
tag: string;
entity: string;
alias?: string;
env?: string;
product?: string;
}
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Source type: database, graph, or vector |
tag | string | Yes | Your data source tag |
entity | string | Yes | Table, node label, or collection name |
alias | string | No | Alias for field references |
env | string | No | Environment (defaults to SDK context) |
product | string | No | Product (defaults to SDK context) |
Operations
Select
Read data from one or more sources:
- TypeScript
const result = await ductape.warehouse.query({
operation: 'select',
from: { type: 'database', tag: 'users-db', entity: 'users', alias: 'u' },
fields: ['u.id', 'u.name', 'u.email'],
where: { 'u.status': { $eq: 'active' } },
orderBy: [{ field: 'u.createdAt', order: 'DESC' }],
limit: 100,
offset: 0
});
Insert
Add new records:
- TypeScript
// Single record
await ductape.warehouse.query({
operation: 'insert',
from: { type: 'database', tag: 'users-db', entity: 'users' },
data: { name: 'John', email: 'john@example.com' },
returning: true
});
// Multiple records
await ductape.warehouse.query({
operation: 'insert',
from: { type: 'database', tag: 'users-db', entity: 'users' },
data: [
{ name: 'John', email: 'john@example.com' },
{ name: 'Jane', email: 'jane@example.com' }
]
});
Update
Modify existing records:
- TypeScript
await ductape.warehouse.query({
operation: 'update',
from: { type: 'database', tag: 'users-db', entity: 'users' },
data: { status: 'inactive', updatedAt: new Date() },
where: { id: { $eq: 123 } },
returning: true
});
Delete
Remove records:
- TypeScript
await ductape.warehouse.query({
operation: 'delete',
from: { type: 'database', tag: 'users-db', entity: 'users' },
where: { status: { $eq: 'deleted' } },
returning: true
});
Upsert
Insert or update based on key:
- TypeScript
await ductape.warehouse.query({
operation: 'upsert',
from: { type: 'database', tag: 'users-db', entity: 'users' },
data: { id: 123, name: 'John', email: 'john@example.com' },
returning: true
});
Field Selection
Basic Fields
- TypeScript
fields: ['id', 'name', 'email']