@acai/query
TypeScript icon, indicating that this package has built-in type declarations

0.7.0-beta.9 • Public • Published

GitHub Build Status Support

Açaí's Framework query builder

A simple modular, scalable query builder that let you toggle strategies to easily, used and created by Açaí Framework.

Supports

  • [x] MySQL
  • [x] PostgreSQL
  • [ ] mongo
  • [ ] sqlite

Installation

npm

npm install --save @acai/query

yarn

yarn add @acai/query

Usage

Setup

The first thing you are going to need is setup your query, you can easily define your default query or just setup one as follows:

import query, { setDefault, addQuery } from "@acai/query";

// Add query of sql type
await addQuery("secondary", "sql", {
  /* sql config */
});
const sqlquery = query("secondary");

// or setup a default query so you can easily import
await setDefaultQuery("pg", {
  /* Optional sql query settings, if you want to pass any */
});

// now every time you call query without arguments, it will look for the default query
const pgquery = query(); // <-- this is a postgreSQL query builder

Querying

You can easily search select using the query

import query from "@acai/query";

const results = await query()
  .table("people")
  .where("id", 5)
  .get(["name", "age"]);

Our query builder smartlys build your raw string query so you don't have to worry about the details, for example:

await query().table("people").where("id", 5).where("name", "Robert").get();

// will output:
// SELECT FROM people WHERE id = 5 AND name = Robert

await query().table("people").where("id", 2).orWhere("name", "Robert").get();

// will output:
// SELECT FROM people WHERE id = 5 OR name = Robert

Inserting

import query from "@acai/query";

await query().table("people").insert({
  name: "John",
  surname: "Doe",
  age: 32,
});

Updating

import query from "@acai/query";

await query().table("people").where("id", 5).update({
  name: "John",
});

Deleting

import query from "@acai/query";

await query().table("people").where("id", 5).delete();

Readme

Keywords

none

Package Sidebar

Install

npm i @acai/query

Weekly Downloads

72

Version

0.7.0-beta.9

License

BSD-3-Clause

Unpacked Size

214 kB

Total Files

10

Last publish

Collaborators

  • darklight98