dwh-client
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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 = new Table<Customer>('customers', axiosInstance);

Insert Data

customerTable.insert({
    name: 'John Doe',
    age: 30,
    street: '123 Main St',
    phone: '123-456-7890',
    email: 'test@gmail.com',
    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: 'test@gmail.com',
    city: 'New York'
})

Insert bulk data

customerTable.insertBulk([
    {
        name: 'John Doe',
        age: 30,
        street: '123 Main St',
        phone: '123-456-7890',
        email: 'test@gmail.com',
        city: 'New York'
    },
    {
        name: 'John Doe 2',
        age: 30,
        street: '123 Main St',
        phone: '123-456-7890',
        email: 'test@gmail.com',
        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;

Readme

Keywords

none

Package Sidebar

Install

npm i dwh-client

Weekly Downloads

2

Version

2.0.0

License

ISC

Unpacked Size

26.9 kB

Total Files

19

Last publish

Collaborators

  • vergodt
  • dencannon