Sharing Top Content from the Angular-sphere.

📦 Cuery: A Composable SQL Query Builder using Template Literals – (Inspired by styled-compo…

  • In 2016, I wrote a blog post about composing SQL queries and published this library as a reference.
  • You can declare helper methods that do magic on your queries, like : – – ; then you can just compose your queries!

GitHub is where people build software. More than 27 million people use GitHub to discover, fork, and contribute to over 80 million projects.

GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.

If nothing happens, download the GitHub extension for Visual Studio and try again.

In 2016, I wrote a blog post about composing SQL queries and published this library as a reference. The years passed, and there are much cooler ways of doing it, so this is the new way – using template literals.

import { sql, execute } from “cuery”; const usersQuery = sql ` SELECT * FROM users`; const usersWithNameQuery = sql ` SELECT * FROM (${usersQuery}) WHERE name = ${ params => params.name } `; execute(usersWithNameQuery, { name: “John” }); // => Promise()

const limit = query => sql ` SELECT * FROM (${query}) limited_query_${ Math.floor(Math.random() * 100000)} LIMIT ${ p => p.limit } OFFSET ${ p => p.offset } `; // then you can just compose your queries! const users = sql ` SELECT * FROM users`; const usersWithLimit = users.compose(limit); // or limit(users) execute(usersWithLimit, { limit: 10, offset: 10 }); // start with offset of 10, then take 10 records.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

GitHub