simpledbi

0.1.3 • Public • Published

simpledbi

A simple Database Interface using TypeScript annotations.

The goal is to write raw SQL (no ORM) and have SQL queries bound to a function execution. It is heavily inspired from JDBI

To use it, you should use one of the real database bindings such as simpledbi-sqlite3 (currently, it's the only binding available BTW, PR are welcome).

Currenly at the stage of a prototype - comments welcome!

Example

Here is what an access layer looks like.

class LoremDao implements SqlProxy {
    constructor(public database: DatabaseAdapter) { }
 
    @SqlScript(`
        DROP TABLE IF EXISTS lorem;
        CREATE TABLE lorem (id NUMBER, info TEXT);
    `)
    createTable(): Promise<SqlRunResult> { throw '' }
 
    @SqlRun(`
        INSERT INTO lorem (id, info)
        VALUES ($id, $info)
    `)
    insert(id: number, info: string): Promise<SqlRunResult> { throw '' }
 
    @SqlGet(`
        SELECT id, info
        FROM lorem
        WHERE id = $id
    `)
    getById(id: number): Promise<LoremRecord> { throw '' }
 
    @SqlQuery(`
        SELECT id, info
        FROM lorem
    `)
    getAll(): Promise<LoremRecord[]> { throw '' }
}
 

Package Sidebar

Install

npm i simpledbi

Weekly Downloads

0

Version

0.1.3

License

MIT

Last publish

Collaborators

  • jvorwerk