dwh-client
v2.0.1
Published
```typescript import { DwhClient, QueryBuilder } from 'dwh-client';
Downloads
3
Readme
Installation
import { DwhClient, QueryBuilder } from 'dwh-client';
const configs = {
baseUrl: 'https://your-dwh-api.com/api/',
version: 'v1',
accessKey: 'your-access-key',
debug: true
};
const dwhClient = new DwhClient(configs);
Create Table
const columns = {
name: "TEXT",
age: "INT",
street: "TEXT",
phone: "TEXT",
email: "TEXT",
city: "TEXT"
};
dwhClient.createTable('customers', columns)
.then((success) => {
console.log('Table created successfully:', success);
})
.catch((error) => {
console.error('Failed to create table:', error);
});
Drop Table
dwhClient.dropTable('customers')
.then((success) => {
console.log('Table dropped successfully:', success);
})
.catch((error) => {
console.error('Failed to drop table:', error);
});
Make your model
interface Customer {
name: string;
age: number;
street: string;
phone: string;
email: string;
city: string;
}
Init Table Instance
const customerTable = dwhClient.table<Customer>('customers');
Insert Data
customerTable.insert({
name: 'John Doe',
age: 30,
street: '123 Main St',
phone: '123-456-7890',
email: '[email protected]',
city: 'New York'
})
Update Data
customerTable.update('a0c83200-f682-11ee-a0cc-2dfdfbfe60bc', {
name: 'John Doe',
age: 30,
street: '123 Main St',
phone: '123-456-7890',
email: '[email protected]',
city: 'New York'
})
Insert bulk data
customerTable.insertBulk([
{
name: 'John Doe',
age: 30,
street: '123 Main St',
phone: '123-456-7890',
email: '[email protected]',
city: 'New York'
},
{
name: 'John Doe 2',
age: 30,
street: '123 Main St',
phone: '123-456-7890',
email: '[email protected]',
city: 'New York'
}
])
Get by ID
customerTable.get(1)
.then((customer) => {
console.log('Customer:', customer);
})
.catch((error) => {
console.error('Failed to get customer:', error);
});
Query Builder
let query = new QueryBuilder();
query = query.match('city', 'New York')
.bool(nested =>
nested.should()
.match('name', 'John Doe')
.rangeGte('age', 30)
)
.mustNot()
.match('phone', '+1')
.limit(0, 100)
.sort('age', 'desc')
.build();
customerTable.query(query)
.then((customers) => {
console.log('Customers:', customers);
})
.catch((error) => {
console.error('Failed to query customers:', error);
});
Query Builder Methods
must(): QueryBuilder;
mustNot(): QueryBuilder;
should(): QueryBuilder;
filter(): QueryBuilder;
bool(nestedQuery: (qb: QueryBuilder) => QueryBuilder): QueryBuilder;
match(field: string, value: any): QueryBuilder;
range(field: string, from: any, to: any): QueryBuilder;
rangeGte(field: string, from: any): QueryBuilder;
rangeLte(field: string, to: any): QueryBuilder;
rangeGt(field: string, from: any): QueryBuilder;
rangeLt(field: string, to: any): QueryBuilder;
term(field: string, value: any): QueryBuilder;
terms(field: string, values: any[]): QueryBuilder;
exists(field: string): QueryBuilder;
prefix(field: string, value: any): QueryBuilder;
wildcard(field: string, value: any): QueryBuilder;
fuzzy(field: string, value: any): QueryBuilder;
limit(from: number, size: number): QueryBuilder;
sort(field: string, order: string): QueryBuilder;