0.0.1 • Published 1 year ago

depresto v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Depresto

This is a super duper mediocre library that allows you to build dynamic prestodb queries from JSON

Implemented Functionality

Basic select queries

const depresto = require('depresto');

const query = depresto({
    from: 'tablename',
    select: ['column_a', 'column_b'],
});
// query = 'SELECT column_a, column_b FROM tablename;'

If the select key is optional and if ommitted will be replaced with *

Simple conditional queries

const query = depresto({
    from: 'tablename',
    where: {
        col_a: 'hello',
        col_b: 'world',
    }
});
// query = 'SELECT * FROM tablename WHERE col_a = 'hello' AND col_b = 'world';

OR conditions

const query = depresto({
    from: 'tablename',
    where: {
        $or: [
            { col_a: 'hello' },
            { col_b: 'world },
        ]
    }
});
// query = SELECT * FROM tablename WHERE (col_a = 'hello' OR col_b = 'world');

OR/AND combined

const query = depresto({
    from: 'tablename',
    where: {
        col_a: 'hello',
        $or: [
            { col_b: 'world' },
            { col_b: 'pat' },
        ]
    }
});
// query = SELECT * FROM tablename WHERE col_a = 'hello' AND (col_b = 'world' OR col_b = 'pat');

IN list

const query = depresto({
    from: 'tablename',
    where: {
        $in: { col_a: [1, 2, 3] },
    }
});
// query = SELECT * FROM tablename WHERE contains(array[1, 2, 3], col_a);

NOT IN list

const query = depresto({
    from: 'tablename',
    where: {
        $notIn: { col_a: [1, 2, 3] },
    }
});
// query = SELECT * FROM tablename WHERE col_a NOT IN array[1, 2, 3];

Comparison operators

const query = depresto({
    from: 'tablename',
    where: {
        $gt: { col_a: 10 },
        $gte: { col_b: 20 },
        $lt: { col_c: 30 },
        $lte: { col_d: 40 },
    }
});
// query = SELECT * FROM tablename WHERE col_a > 10 AND col_b >= 20 AND col_c < 30 AND col_d <= 40;
0.0.1

1 year ago