Skip to content

tmonte/tsql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tsql

simple typesafe json query language

install

npm install --save-dev git+https://github.com/tmonte/tsql.git

usage example

Interfaces

// Define the model
interface IFruitBasket {
    readonly apple: string
    readonly grape: number
    readonly passionfruit: "a" | "b"
    readonly box: {
        readonly orange: boolean
    }
}

// Define the operation
interface IFruitBasketService {
    readonly filter: tsql.IFilter<IFruitBasket>
}

Implementation

declare const fbs: IFruitBasketService; // = new FruitBasketService();

const result = fbs.filter({
    select: <const>{ // this const assertion is required
        apple: "apple",
        grape: "grape",
        passionfruit: "delicious",
        box: {
            orange: "orange"
        },
    },
    where: [
        { apple: { eq: 'hello' } },
        'and',
        { grape: { gt: 32 } }
    ],
    order: {
        apple: 'desc',
        grape: 'asc'
    },
    limit: 10,
    offset: 0
});

if (result.kind == 'success') {
    const { delicious } = result.value[0];
    const { orange } = result.value[1].box;
    // ...
}

About

simple typesafe json query language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published