@acai/query 中文文档教程

发布于 3年前 浏览 21 项目主页 更新于 3年前

GitHub 构建状态”></a> <a href=Support

Açaí's Framework query builder

一个简单的模块化、可扩展的查询构建器,可让您轻松切换策略,由 Açaí Framework 使用和创建。

Supports

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

Installation

npm

npm install --save @acai/query

yarn

yarn add @acai/query

Usage

Setup

您需要做的第一件事是设置您的查询,您可以轻松定义您的默认查询或仅设置一个如下:

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

您可以使用查询轻松搜索选择

import query from "@acai/query";

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

我们的查询构建器巧妙地构建您的原始字符串查询,这样您就不会不必担心细节,例如:

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();

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();
更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文