1. @sqorn/pg
A Javascript library for building Postgres queries
@sqorn/pg
Package: @sqorn/pg
Created by: sqorn
Last modified: Sat, 17 Dec 2022 13:50:13 GMT
Version: 0.0.45
License: MIT
Downloads: 721
Repository: https://github.com/sqorn/sqorn/tree/master/packages/sqorn-pg

Install

npm install @sqorn/pg
yarn add @sqorn/pg

Sqorn Postgres · License npm Supports Node 8+ npm

Sqorn Postgres is a Javascript library for building SQL queries.

Composable: Build complex queries from simple parts. Chain, extend, and embed queries.

Intuitive: Sqorn's use of modern Javascript language features like tagged template literals and promises makes building and issuing SQL queries a breeze.

Concise: Sqorn provides concise syntax for common CRUD operations.

Fast: 10x faster than Knex.js and 200x faster than Squel

Secure: Sqorn generates parameterized queries safe from SQL injection. Sqorn has no external dependencies.

Install

Sqorn requires Node version 8 or above.

 npm install --save @sqorn/pg # only Postgres is currently supported

Then read the tutorial and try the online demo.

Examples

CRUD Operations are dead simple.

 const sq = require('@sqorn/pg')()

const Person = sq`person`, Book = sq`book`

// SELECT
const children = await Person`age < ${13}`
// "select * from person where age < 13"

// DELETE
const [deleted] = await Book.delete({ id: 7 })`title`
// "delete from book where id = 7 returning title"

// INSERT
await Person.insert({ firstName: 'Rob' })
// "insert into person (first_name) values ('Rob')"

// UPDATE
await Person({ id: 23 }).set({ name: 'Rob' })
// "update person set name = 'Rob' where id = 23"

Build complex queries from simple parts.

 // CHAIN QUERIES
sq.from`book`
  .return`distinct author`
  .where({ genre: 'Fantasy' })
  .where({ language: 'French' })
// select distinct author from book
// where language = 'French' and genre = 'Fantasy'

// EXTEND QUERIES
sq.extend(
  sq.from`book`,
  sq.return`distinct author`,
  sq.where({ genre: 'Fantasy' }),
  sq.where({ language: 'French' })
)
// select distinct author from book
// where language = 'French' and genre = 'Fantasy'

// EMBED Queries
sq.return`now() today, (${sq.return`now() + '1 day'`}) tomorrow`
// select now() today, (select now() + '1 day') tomorrow

Learn more in the tutorial.

License

MIT Licensed, Copyright (c) 2018 Sufyan Dawoodjee

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin