Code Monkey home page Code Monkey logo

sqorn's Introduction

Sqorn · License npm Supports Node 8+ npm PRs Welcome

Sqorn is a Javascript library for building SQL queries.

Ergonomic: Sqorn's intuitive API might make you forget you're building SQL.

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

Boilerplate free: Sqorn provides concise syntax for common CRUD operations.

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

Install

Sqorn requires Node version 8 or above.

npm install --save sqorn
npm install --save 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')()

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.del({ id: 7 })`title`
// "delete from book where id = 7 returning title"

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

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

Build complex queries from simple parts.

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

// EXTEND QUERIES
sq.ext(
  sq.frm`book`,
  sq.ret`distinct author`,
  sq.whr({ genre: 'Fantasy' }),
  sq.whr({ language: 'French' })
)
// select distinct author from book
// where language = 'French' and genre = 'Fantsy'

// EMBED Queries
sq.ret`now() today, ${sq.ret`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

sqorn's People

Contributors

eejdoowad avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.