New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sql-qb

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql-qb

Sql query builder for pg for educational purposes

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

sql-query-builder

Sql query builder for educational purposes

Select:

    const { rows: user } = await db
        .select({
            username: 'rs-hub'
        })
        .table("users")
        .column(["id", "username"])
        .limit(1)
        .skip(1)
        .query();

    console.log(user); // [ { id: 8, username: 'rs-hub' } ]

Insert:

     const { rows } = await db
         .insert({
                username: 'michael',
            })
         .table('users')
         .returning(['id', 'username'])
         .query();

     console.log(rows); // [ { id: 12, username: 'michael' } ]

Create Table:

    const newTable = await db.createTable({
        id: {
            type: 'id',
        },
        comment: {
            type: 'text',
            constraints: ['notNull', 'unique']
        },
        userId: {
            type: 'int',
            constraints: ['notNull'],
            references: {
                table: 'users',
                field: 'id',
                method: 'onDeleteCascade',
            }
        }
    })
      .table('comments')
      .ifNotExist()
      .query();
    console.log('createTable');

Update:

    const update = await db
        .update({
            id: 6,
            username: 'rs-hub'
        })
        .table('users')
        .set({
            username: 'rs-hub',
        })
        .query();
    console.log(update);

Join:

     const { rows } = await db
         .select({
                username: 'rs-hub'
            })
         .table("users")
         .column(["users.id as userId", "posts.id as postId", "posts.text as postsText", "comments.comment"])
         .innerJoin({
                tables: ['posts', 'comments'],
                conditions: ['users.id = posts.userid', 'comments.postsid = posts.id']
            })
         .limit(1)
         .skip(1)
         .query();
         console.log(rows) // [ { userid: 8, postid: 1, poststext: 'hello', comment: 'Good' } ];

FAQs

Package last updated on 19 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts