Have ideas to improve npm?Join in the discussion! »

    pg-prepare

    2.0.1 • Public • Published

    PostgreSQL prepared statements via ES6 Template Literals (string interpolation)

    Usage

    const prepare = require('pg-prepare');
     
    ...
    const firstName = 'Foo';
    const lastName = 'Bar';
     
    let stmt = prepare`SELECT ${firstName}::text AS first_name, ${lastName}::text AS last_name`;
    console.log('Statement:', stmt); //{ text: 'SELECT $1::text AS first_name, $2::text AS last_name', values: ['Foo', 'Bar'] }
     
    let result = await client.query(stmt);
    console.log('Result:', result.rows[0]); //{ first_name: 'Foo', last_name: 'Bar' }

    See also:

    License

    MIT http://eib.mit-license.org/

    Install

    npm i pg-prepare

    DownloadsWeekly Downloads

    3

    Version

    2.0.1

    License

    MIT

    Last publish

    Collaborators

    • avatar