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
- Java
- Go
- .NET
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
});
Map<String, Object> result = ductape.warehouse.query(Map.of(
"operation", "select",
from: Map.of( "type", "database", "tag", "users-db", "entity", "users", "alias", "u" ),
fields: ['u.id', 'u.name', 'u.email'],
where: Map.of( 'u.status': Map.of( $"eq", "active" ) ),
orderBy: [Map.of( "field", "u.createdAt", "order", "DESC" )],
"limit", 100,
"offset", 0
));
result := client.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
});
var 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
- Java
- Go
- .NET
// 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' }
]
});
// Single record
ductape.warehouse.query(Map.of(
"operation", "insert",
from: Map.of( "type", "database", "tag", "users-db", "entity", "users" ),
data: Map.of( "name", "John", "email", "john@example.com" ),
"returning", true
));
// Multiple records
ductape.warehouse.query(Map.of(
"operation", "insert",
from: Map.of( "type", "database", "tag", "users-db", "entity", "users" ),
data: [
Map.of( "name", "John", "email", "john@example.com" ),
Map.of( "name", "Jane", "email", "jane@example.com" )
]
));
// Single record
client.warehouse.query({
"operation": "insert",
from: { "type": "database", "tag": "users-db", "entity": "users" },
data: { "name": "John", "email": "john@example.com" },
"returning": true
});
// Multiple records
client.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" }
]
});
// 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
- Java
- Go
- .NET
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
});
ductape.warehouse.query(Map.of(
"operation", "update",
from: Map.of( "type", "database", "tag", "users-db", "entity", "users" ),
data: Map.of( "status", "inactive", updatedAt: Instant.now() ),
where: Map.of( id: Map.of( $"eq", 123 ) ),
"returning", true
));
client.warehouse.query({
"operation": "update",
from: { "type": "database", "tag": "users-db", "entity": "users" },
data: { "status": "inactive", updatedAt: new Date() },
where: { id: { $"eq": 123 } },
"returning": true
});
await ductape.warehouse.query({
["operation"] = "update",
from: { ["type"] = "database", ["tag"] = "users-db", ["entity"] = "users" },
data: { ["status"] = "inactive", updatedAt: DateTime.UtcNow },
where: { id: { $["eq"] = 123 } },
["returning"] = true
});
Delete
Remove records:
- TypeScript
- Java
- Go
- .NET
await ductape.warehouse.query({
operation: 'delete',
from: { type: 'database', tag: 'users-db', entity: 'users' },
where: { status: { $eq: 'deleted' } },
returning: true
});
ductape.warehouse.query(Map.of(
"operation", "delete",
from: Map.of( "type", "database", "tag", "users-db", "entity", "users" ),
where: Map.of( status: Map.of( $"eq", "deleted" ) ),
"returning", true
));
client.warehouse.query({
"operation": "delete",
from: { "type": "database", "tag": "users-db", "entity": "users" },
where: { status: { $"eq": "deleted" } },
"returning": true
});
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
- Java
- Go
- .NET
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
});
ductape.warehouse.query(Map.of(
"operation", "upsert",
from: Map.of( "type", "database", "tag", "users-db", "entity", "users" ),
data: Map.of( "id", 123, "name", "John", "email", "john@example.com" ),
"returning", true
));
client.warehouse.query({
"operation": "upsert",
from: { "type": "database", "tag": "users-db", "entity": "users" },
data: { "id": 123, "name": "John", "email": "john@example.com" },
"returning": true
});
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
- Java
- Go
- .NET
fields: ['id', 'name', 'email']
fields: ['id', 'name', 'email']
fields: ['id', 'name', 'email']
fields: ['id', 'name', 'email']
With Alias Reference
- TypeScript
- Java
- Go
- .NET
fields: ['u.id', 'u.name', 'u.email']
fields: ['u.id', 'u.name', 'u.email']
fields: ['u.id', 'u.name', 'u.email']
fields: ['u.id', 'u.name', 'u.email']
Field Aliasing
- TypeScript
- Java
- Go
- .NET
fields: [
'u.id',
'u.name',
'u.email as userEmail',
'o.total as orderTotal'
]
fields: [
'u.id',
'u.name',
'u.email as userEmail',
'o.total as orderTotal'
]
fields: [
'u.id',
'u.name',
'u.email as userEmail',
'o.total as orderTotal'
]
fields: [
'u.id',
'u.name',
'u.email as userEmail',
'o.total as orderTotal'
]
Wildcard
- TypeScript
- Java
- Go
- .NET
fields: ['*'] // All fields from primary source
fields: ['u.*', 'o.total'] // All from u, specific from o
fields: ['*'] // All fields from primary source
fields: ['u.*', 'o.total'] // All from u, specific from o
fields: ['*'] // All fields from primary source
fields: ['u.*', 'o.total'] // All from u, specific from o
fields: ['*'] // All fields from primary source
fields: ['u.*', 'o.total'] // All from u, specific from o
Where Clauses
Comparison Operators
| Operator | Description | Example |
|---|---|---|
$eq | Equal | { status: { $eq: 'active' } } |
$ne | Not equal | { status: { $ne: 'deleted' } } |
$gt | Greater than | { age: { $gt: 18 } } |
$gte | Greater than or equal | { age: { $gte: 18 } } |
$lt | Less than | { age: { $lt: 65 } } |
$lte | Less than or equal | { age: { $lte: 65 } } |
- TypeScript
- Java
- Go
- .NET
where: {
'u.age': { $gte: 18, $lt: 65 },
'u.status': { $eq: 'active' }
}
where: Map.of(
'u.age': Map.of( $"gte", 18, $"lt", 65 ),
'u.status': Map.of( $"eq", "active" )
)
where: {
'u.age': { $"gte": 18, $"lt": 65 },
'u.status': { $"eq": "active" }
}
where: {
'u.age': { $["gte"] = 18, $["lt"] = 65 },
'u.status': { $["eq"] = "active" }
}
Logical Operators
| Operator | Description | Example |
|---|---|---|
$and | Logical AND | { $and: [cond1, cond2] } |
$or | Logical OR | { $or: [cond1, cond2] } |
$not | Logical NOT | { $not: condition } |
- TypeScript
- Java
- Go
- .NET
where: {
$and: [
{ 'u.status': { $eq: 'active' } },
{
$or: [
{ 'u.role': { $eq: 'admin' } },
{ 'u.role': { $eq: 'moderator' } }
]
}
]
}
where: Map.of(
$and: [
Map.of( 'u.status': Map.of( $"eq", "active" ) ),
Map.of(
$or: [
Map.of( 'u.role': Map.of( $"eq", "admin" ) ),
Map.of( 'u.role': Map.of( $"eq", "moderator" ) )
]
)
]
)
where: {
$and: [
{ 'u.status': { $"eq": "active" } },
{
$or: [
{ 'u.role': { $"eq": "admin" } },
{ 'u.role': { $"eq": "moderator" } }
]
}
]
}
where: {
$and: [
{ 'u.status': { $["eq"] = "active" } },
{
$or: [
{ 'u.role': { $["eq"] = "admin" } },
{ 'u.role': { $["eq"] = "moderator" } }
]
}
]
}
Array Operators
| Operator | Description | Example |
|---|---|---|
$in | In array | { role: { $in: ['admin', 'mod'] } } |
$nin | Not in array | { role: { $nin: ['banned'] } } |
$contains | Array contains | { tags: { $contains: 'featured' } } |
$containsAll | Contains all | { tags: { $containsAll: ['a', 'b'] } } |
$containsAny | Contains any | { tags: { $containsAny: ['a', 'b'] } } |
- TypeScript
- Java
- Go
- .NET
where: {
'u.roles': { $in: ['admin', 'moderator'] },
'u.tags': { $containsAll: ['verified', 'premium'] }
}
where: Map.of(
'u.roles': Map.of( $in: ['admin', 'moderator'] ),
'u.tags': Map.of( $containsAll: ['verified', 'premium'] )
)
where: {
'u.roles': { $in: ['admin', 'moderator'] },
'u.tags': { $containsAll: ['verified', 'premium'] }
}
where: {
'u.roles': { $in: ['admin', 'moderator'] },
'u.tags': { $containsAll: ['verified', 'premium'] }
}
String Operators
| Operator | Description | Example |
|---|---|---|
$like | Pattern match | { email: { $like: '%@company.com' } } |
$ilike | Case-insensitive like | { name: { $ilike: 'john%' } } |
$regex | Regular expression | { email: { $regex: '^[a-z]+@' } } |
$startsWith | Starts with | { name: { $startsWith: 'John' } } |
$endsWith | Ends with | { email: { $endsWith: '.com' } } |
- TypeScript
- Java
- Go
- .NET
where: {
'u.email': { $like: '%@company.com' },
'u.name': { $ilike: 'john%' }
}
where: Map.of(
'u.email': Map.of( $"like", "%@company.com" ),
'u.name': Map.of( $"ilike", "john%" )
)
where: {
'u.email': { $"like": "%@company.com" },
'u.name': { $"ilike": "john%" }
}
where: {
'u.email': { $["like"] = "%@company.com" },
'u.name': { $["ilike"] = "john%" }
}
Null Operators
| Operator | Description | Example |
|---|---|---|
$null | Is null | { deletedAt: { $null: true } } |
$exists | Field exists | { metadata: { $exists: true } } |
- TypeScript
- Java
- Go
- .NET
where: {
'u.deletedAt': { $null: true },
'u.profile': { $exists: true }
}
where: Map.of(
'u.deletedAt': Map.of( $"null", true ),
'u.profile': Map.of( $"exists", true )
)
where: {
'u.deletedAt': { $"null": true },
'u.profile': { $"exists": true }
}
where: {
'u.deletedAt': { $["null"] = true },
'u.profile': { $["exists"] = true }
}
Vector Operators
| Operator | Description | Example |
|---|---|---|
$similar | Vector similarity | { $similar: { vector: [...], threshold: 0.7 } } |
$near | Distance-based | { $near: { vector: [...], maxDistance: 0.5 } } |
- TypeScript
- Java
- Go
- .NET
where: {
'v': {
$similar: {
vector: queryEmbedding,
threshold: 0.7,
topK: 10
}
}
}
where: Map.of(
'v': Map.of(
$similar: Map.of(
vector: queryEmbedding,
"threshold", 0.7,
"topK", 10
)
)
)
where: {
'v': {
$similar: {
vector: queryEmbedding,
"threshold": 0.7,
"topK": 10
}
}
}
where: {
'v': {
$similar: {
vector: queryEmbedding,
["threshold"] = 0.7,
["topK"] = 10
}
}
}
Join Clauses
Standard Join
- TypeScript
- Java
- Go
- .NET
join: [{
type: 'inner' | 'left' | 'right',
source: IDataSource,
on: { left: string, right: string },
where?: IWhereClause
}]
join: [Map.of(
"type", "inner" | 'left' | 'right',
source: IDataSource,
on: Map.of( left: string, right: string ),
where?: IWhereClause
)]
join: [{
"type": "inner" | 'left' | 'right',
source: IDataSource,
on: { left: string, right: string },
where?: IWhereClause
}]
join: [{
["type"] = "inner" | 'left' | 'right',
source: IDataSource,
on: { left: string, right: string },
where?: IWhereClause
}]
Graph Join
- TypeScript
- Java
- Go
- .NET
join: [{
type: 'left',
source: { type: 'graph', tag: 'social-neo4j', entity: 'Person', alias: 'f' },
graph: {
relationship: 'FRIENDS_WITH',
direction: 'outgoing' | 'incoming' | 'both',
minDepth?: number,
maxDepth?: number
},
on: { left: 'u.id', right: 'f.userId' }
}]
join: [Map.of(
"type", "left",
source: Map.of( "type", "graph", "tag", "social-neo4j", "entity", "Person", "alias", "f" ),
graph: Map.of(
"relationship", "FRIENDS_WITH",
"direction", "outgoing" | 'incoming' | 'both',
minDepth?: number,
maxDepth?: number
),
on: Map.of( "left", "u.id", "right", "f.userId" )
)]
join: [{
"type": "left",
source: { "type": "graph", "tag": "social-neo4j", "entity": "Person", "alias": "f" },
graph: {
"relationship": "FRIENDS_WITH",
"direction": "outgoing" | 'incoming' | 'both',
minDepth?: number,
maxDepth?: number
},
on: { "left": "u.id", "right": "f.userId" }
}]
join: [{
["type"] = "left",
source: { ["type"] = "graph", ["tag"] = "social-neo4j", ["entity"] = "Person", ["alias"] = "f" },
graph: {
["relationship"] = "FRIENDS_WITH",
["direction"] = "outgoing" | 'incoming' | 'both',
minDepth?: number,
maxDepth?: number
},
on: { ["left"] = "u.id", ["right"] = "f.userId" }
}]
Semantic Join
- TypeScript
- Java
- Go
- .NET
join: [{
type: 'semantic',
source: { type: 'vector', tag: 'embeddings', entity: 'items', alias: 's' },
semantic: {
embedField?: string,
vector?: number[],
similarityThreshold?: number,
topK?: number
}
}]
join: [Map.of(
"type", "semantic",
source: Map.of( "type", "vector", "tag", "embeddings", "entity", "items", "alias", "s" ),
semantic: Map.of(
embedField?: string,
vector?: number[],
similarityThreshold?: number,
topK?: number
)
)]
join: [{
"type": "semantic",
source: { "type": "vector", "tag": "embeddings", "entity": "items", "alias": "s" },
semantic: {
embedField?: string,
vector?: number[],
similarityThreshold?: number,
topK?: number
}
}]
join: [{
["type"] = "semantic",
source: { ["type"] = "vector", ["tag"] = "embeddings", ["entity"] = "items", ["alias"] = "s" },
semantic: {
embedField?: string,
vector?: number[],
similarityThreshold?: number,
topK?: number
}
}]
Ordering
- TypeScript
- Java
- Go
- .NET
orderBy: [
{ field: 'createdAt', order: 'DESC' },
{ field: 'name', order: 'ASC' }
]
orderBy: [
Map.of( "field", "createdAt", "order", "DESC" ),
Map.of( "field", "name", "order", "ASC" )
]
orderBy: [
{ "field": "createdAt", "order": "DESC" },
{ "field": "name", "order": "ASC" }
]
orderBy: [
{ ["field"] = "createdAt", ["order"] = "DESC" },
{ ["field"] = "name", ["order"] = "ASC" }
]
Pagination
- TypeScript
- Java
- Go
- .NET
{
limit: 20,
offset: 40 // Skip first 40 records
}
Map.of(
"limit", 20,
"offset", 40 // Skip first 40 records
)
{
"limit": 20,
"offset": 40 // Skip first 40 records
}
{
["limit"] = 20,
["offset"] = 40 // Skip first 40 records
}
Aggregations
Group By
- TypeScript
- Java
- Go
- .NET
{
operation: 'select',
from: { type: 'database', tag: 'orders-db', entity: 'orders', alias: 'o' },
fields: [
'o.status',
{ $count: '*', as: 'count' },
{ $sum: 'o.total', as: 'totalAmount' },
{ $avg: 'o.total', as: 'avgAmount' }
],
groupBy: ['o.status'],
having: { 'count': { $gt: 10 } }
}
Map.of(
"operation", "select",
from: Map.of( "type", "database", "tag", "orders-db", "entity", "orders", "alias", "o" ),
fields: [
'o.status',
Map.of( $"count", "*", "as", "count" ),
Map.of( $"sum", "o.total", "as", "totalAmount" ),
Map.of( $"avg", "o.total", "as", "avgAmount" )
],
groupBy: ['o.status'],
having: Map.of( 'count': Map.of( $"gt", 10 ) )
)
{
"operation": "select",
from: { "type": "database", "tag": "orders-db", "entity": "orders", "alias": "o" },
fields: [
'o.status',
{ $"count": "*", "as": "count" },
{ $"sum": "o.total", "as": "totalAmount" },
{ $"avg": "o.total", "as": "avgAmount" }
],
groupBy: ['o.status'],
having: { 'count': { $"gt": 10 } }
}
{
["operation"] = "select",
from: { ["type"] = "database", ["tag"] = "orders-db", ["entity"] = "orders", ["alias"] = "o" },
fields: [
'o.status',
{ $["count"] = "*", ["as"] = "count" },
{ $["sum"] = "o.total", ["as"] = "totalAmount" },
{ $["avg"] = "o.total", ["as"] = "avgAmount" }
],
groupBy: ['o.status'],
having: { 'count': { $["gt"] = 10 } }
}
Aggregate Functions
| Function | Description | Example |
|---|---|---|
$count | Count records | { $count: '*', as: 'total' } |
$sum | Sum values | { $sum: 'amount', as: 'total' } |
$avg | Average | { $avg: 'rating', as: 'avgRating' } |
$min | Minimum | { $min: 'price', as: 'minPrice' } |
$max | Maximum | { $max: 'price', as: 'maxPrice' } |
Update Operators
Special operators for update operations:
| Operator | Description | Example |
|---|---|---|
$increment | Add to value | { count: { $increment: 1 } } |
$decrement | Subtract from value | { stock: { $decrement: 1 } } |
$multiply | Multiply value | { price: { $multiply: 1.1 } } |
$push | Add to array | { tags: { $push: 'new' } } |
$pull | Remove from array | { tags: { $pull: 'old' } } |
- TypeScript
- Java
- Go
- .NET
await ductape.warehouse.query({
operation: 'update',
from: { type: 'database', tag: 'products-db', entity: 'products' },
data: {
viewCount: { $increment: 1 },
stock: { $decrement: quantity },
tags: { $push: 'bestseller' }
},
where: { id: { $eq: productId } }
});
ductape.warehouse.query(Map.of(
"operation", "update",
from: Map.of( "type", "database", "tag", "products-db", "entity", "products" ),
data: Map.of(
viewCount: Map.of( $"increment", 1 ),
stock: Map.of( $decrement: quantity ),
tags: Map.of( $"push", "bestseller" )
),
where: Map.of( id: Map.of( $eq: productId ) )
));
client.warehouse.query({
"operation": "update",
from: { "type": "database", "tag": "products-db", "entity": "products" },
data: {
viewCount: { $"increment": 1 },
stock: { $decrement: quantity },
tags: { $"push": "bestseller" }
},
where: { id: { $eq: productId } }
});
await ductape.warehouse.query({
["operation"] = "update",
from: { ["type"] = "database", ["tag"] = "products-db", ["entity"] = "products" },
data: {
viewCount: { $["increment"] = 1 },
stock: { $decrement: quantity },
tags: { $["push"] = "bestseller" }
},
where: { id: { $eq: productId } }
});
Result Structure
interface IWarehouseResult<T> {
data: T[];
count?: number;
affectedRows?: number;
metadata: {
executionTime: number;
sourcesQueried: number;
sourceStats: ISourceStats[];
cached: boolean;
};
}
Examples
Complex Query
- TypeScript
- Java
- Go
- .NET
const result = await ductape.warehouse.query({
operation: 'select',
from: {
type: 'database',
tag: 'users-postgres',
entity: 'users',
alias: 'u'
},
fields: [
'u.id',
'u.name',
'u.email',
'o.orderId',
'o.total',
'p.name as productName',
'r.rating'
],
join: [
{
type: 'left',
source: { type: 'database', tag: 'orders-mongo', entity: 'orders', alias: 'o' },
on: { left: 'u.id', right: 'o.userId' },
where: { 'o.status': { $eq: 'completed' } }
},
{
type: 'inner',
source: { type: 'database', tag: 'products-postgres', entity: 'products', alias: 'p' },
on: { left: 'o.productId', right: 'p.id' }
},
{
type: 'left',
source: { type: 'database', tag: 'reviews-mongo', entity: 'reviews', alias: 'r' },
on: { left: 'p.id', right: 'r.productId' }
}
],
where: {
$and: [
{ 'u.status': { $eq: 'active' } },
{ 'u.createdAt': { $gte: new Date('2024-01-01') } },
{
$or: [
{ 'o.total': { $gte: 100 } },
{ 'r.rating': { $gte: 4 } }
]
}
]
},
orderBy: [
{ field: 'o.total', order: 'DESC' },
{ field: 'u.name', order: 'ASC' }
],
limit: 50,
offset: 0
});
Map<String, Object> result = ductape.warehouse.query(Map.of(
"operation", "select",
from: Map.of(
"type", "database",
"tag", "users-postgres",
"entity", "users",
"alias", "u"
),
fields: [
'u.id',
'u.name',
'u.email',
'o.orderId',
'o.total',
'p.name as productName',
'r.rating'
],
join: [
Map.of(
"type", "left",
source: Map.of( "type", "database", "tag", "orders-mongo", "entity", "orders", "alias", "o" ),
on: Map.of( "left", "u.id", "right", "o.userId" ),
where: Map.of( 'o.status': Map.of( $"eq", "completed" ) )
),
Map.of(
"type", "inner",
source: Map.of( "type", "database", "tag", "products-postgres", "entity", "products", "alias", "p" ),
on: Map.of( "left", "o.productId", "right", "p.id" )
),
Map.of(
"type", "left",
source: Map.of( "type", "database", "tag", "reviews-mongo", "entity", "reviews", "alias", "r" ),
on: Map.of( "left", "p.id", "right", "r.productId" )
)
],
where: Map.of(
$and: [
Map.of( 'u.status': Map.of( $"eq", "active" ) ),
Map.of( 'u.createdAt': Map.of( $gte: new Date('2024-01-01') ) ),
Map.of(
$or: [
Map.of( 'o.total': Map.of( $"gte", 100 ) ),
Map.of( 'r.rating': Map.of( $"gte", 4 ) )
]
)
]
),
orderBy: [
Map.of( "field", "o.total", "order", "DESC" ),
Map.of( "field", "u.name", "order", "ASC" )
],
"limit", 50,
"offset", 0
));
result := client.warehouse.query({
"operation": "select",
from: {
"type": "database",
"tag": "users-postgres",
"entity": "users",
"alias": "u"
},
fields: [
'u.id',
'u.name',
'u.email',
'o.orderId',
'o.total',
'p.name as productName',
'r.rating'
],
join: [
{
"type": "left",
source: { "type": "database", "tag": "orders-mongo", "entity": "orders", "alias": "o" },
on: { "left": "u.id", "right": "o.userId" },
where: { 'o.status': { $"eq": "completed" } }
},
{
"type": "inner",
source: { "type": "database", "tag": "products-postgres", "entity": "products", "alias": "p" },
on: { "left": "o.productId", "right": "p.id" }
},
{
"type": "left",
source: { "type": "database", "tag": "reviews-mongo", "entity": "reviews", "alias": "r" },
on: { "left": "p.id", "right": "r.productId" }
}
],
where: {
$and: [
{ 'u.status': { $"eq": "active" } },
{ 'u.createdAt': { $gte: new Date('2024-01-01') } },
{
$or: [
{ 'o.total': { $"gte": 100 } },
{ 'r.rating': { $"gte": 4 } }
]
}
]
},
orderBy: [
{ "field": "o.total", "order": "DESC" },
{ "field": "u.name", "order": "ASC" }
],
"limit": 50,
"offset": 0
});
var result = await ductape.warehouse.query({
["operation"] = "select",
from: {
["type"] = "database",
["tag"] = "users-postgres",
["entity"] = "users",
["alias"] = "u"
},
fields: [
'u.id',
'u.name',
'u.email',
'o.orderId',
'o.total',
'p.name as productName',
'r.rating'
],
join: [
{
["type"] = "left",
source: { ["type"] = "database", ["tag"] = "orders-mongo", ["entity"] = "orders", ["alias"] = "o" },
on: { ["left"] = "u.id", ["right"] = "o.userId" },
where: { 'o.status': { $["eq"] = "completed" } }
},
{
["type"] = "inner",
source: { ["type"] = "database", ["tag"] = "products-postgres", ["entity"] = "products", ["alias"] = "p" },
on: { ["left"] = "o.productId", ["right"] = "p.id" }
},
{
["type"] = "left",
source: { ["type"] = "database", ["tag"] = "reviews-mongo", ["entity"] = "reviews", ["alias"] = "r" },
on: { ["left"] = "p.id", ["right"] = "r.productId" }
}
],
where: {
$and: [
{ 'u.status': { $["eq"] = "active" } },
{ 'u.createdAt': { $gte: new Date('2024-01-01') } },
{
$or: [
{ 'o.total': { $["gte"] = 100 } },
{ 'r.rating': { $["gte"] = 4 } }
]
}
]
},
orderBy: [
{ ["field"] = "o.total", ["order"] = "DESC" },
{ ["field"] = "u.name", ["order"] = "ASC" }
],
["limit"] = 50,
["offset"] = 0
});
Aggregation Query
- TypeScript
- Java
- Go
- .NET
const result = await ductape.warehouse.query({
operation: 'select',
from: {
type: 'database',
tag: 'orders-postgres',
entity: 'orders',
alias: 'o'
},
fields: [
'o.userId',
{ $count: '*', as: 'orderCount' },
{ $sum: 'o.total', as: 'totalSpent' },
{ $avg: 'o.total', as: 'avgOrder' },
{ $max: 'o.total', as: 'largestOrder' }
],
where: {
'o.createdAt': { $gte: new Date('2024-01-01') },
'o.status': { $eq: 'completed' }
},
groupBy: ['o.userId'],
having: { 'orderCount': { $gte: 5 } },
orderBy: [{ field: 'totalSpent', order: 'DESC' }],
limit: 100
});
Map<String, Object> result = ductape.warehouse.query(Map.of(
"operation", "select",
from: Map.of(
"type", "database",
"tag", "orders-postgres",
"entity", "orders",
"alias", "o"
),
fields: [
'o.userId',
Map.of( $"count", "*", "as", "orderCount" ),
Map.of( $"sum", "o.total", "as", "totalSpent" ),
Map.of( $"avg", "o.total", "as", "avgOrder" ),
Map.of( $"max", "o.total", "as", "largestOrder" )
],
where: Map.of(
'o.createdAt': Map.of( $gte: new Date('2024-01-01') ),
'o.status': Map.of( $"eq", "completed" )
),
groupBy: ['o.userId'],
having: Map.of( 'orderCount': Map.of( $"gte", 5 ) ),
orderBy: [Map.of( "field", "totalSpent", "order", "DESC" )],
"limit", 100
));
result := client.warehouse.query({
"operation": "select",
from: {
"type": "database",
"tag": "orders-postgres",
"entity": "orders",
"alias": "o"
},
fields: [
'o.userId',
{ $"count": "*", "as": "orderCount" },
{ $"sum": "o.total", "as": "totalSpent" },
{ $"avg": "o.total", "as": "avgOrder" },
{ $"max": "o.total", "as": "largestOrder" }
],
where: {
'o.createdAt': { $gte: new Date('2024-01-01') },
'o.status': { $"eq": "completed" }
},
groupBy: ['o.userId'],
having: { 'orderCount': { $"gte": 5 } },
orderBy: [{ "field": "totalSpent", "order": "DESC" }],
"limit": 100
});
var result = await ductape.warehouse.query({
["operation"] = "select",
from: {
["type"] = "database",
["tag"] = "orders-postgres",
["entity"] = "orders",
["alias"] = "o"
},
fields: [
'o.userId',
{ $["count"] = "*", ["as"] = "orderCount" },
{ $["sum"] = "o.total", ["as"] = "totalSpent" },
{ $["avg"] = "o.total", ["as"] = "avgOrder" },
{ $["max"] = "o.total", ["as"] = "largestOrder" }
],
where: {
'o.createdAt': { $gte: new Date('2024-01-01') },
'o.status': { $["eq"] = "completed" }
},
groupBy: ['o.userId'],
having: { 'orderCount': { $["gte"] = 5 } },
orderBy: [{ ["field"] = "totalSpent", ["order"] = "DESC" }],
["limit"] = 100
});