@builder.io/sqlgenerate

中文文档
1.2.9发布于 2021/06/02MITCommonJS近 30 天下载 3014

Generates SQL from a JSON AST.

原始使用文档
文档目录6 节
  1. Overview
  2. Features
  3. Installation
  4. Using this project
  5. Credits
  6. Issues

Overview | Features | Installation | Credits | Issues


Overview

SQLGenerate takes the Codeschool sqlite-parser AST and generates SQL from it. This allows you to read code (using the Codeschool parser), manipulate the AST (using SQLTraverse) and then generate SQL (using this library :smile:).

⬆️

Features

⬆️

Installation

npm install sqlgenerator 👍 done!

⬆️

Using this project

The blow example is a simple case of parsing SQL to an ast and then back again to SQL. One of the better use case for this is to modify your SQL somehow. To do this you can use sqltraverse (yes it's a shameless plug 😁).

import parser       from 'sqlite-parser';
import { generate } from 'sqlgenerate';
import { format }   from "sql-formatter";

const example = `
  SELECT m.title, r.id AS [Theatre Number]
  FROM Movies AS m
  INNER JOIN (
    SELECT r2.movie_id
    FROM Rooms AS r2
    WHERE (r2.seats >= 50)
  ) AS r
  ON ((m.id = r.movie_id) AND (m.title != 'Batman'));`

const ast = parser(sql);
const regeneratedSQL = generate(ast);

console.log(format(regeneratedSQL));

⬆️

Credits

jdrew1303

Copyright (c) 2016

Issues

  • Tests, tests and more tests.
  • Documentation currently under construction (The examples need to be worked through for SQL instead of JavaScript).
  • AST is currently in a state of flux for some node types. We also probably need a builder for these nodes (another project).
  • You need to pass in ast.statement and not just the raw ast given back from the parser (This is an issue with the base node not having a type).
  • Adding support for comments.
  • Adding support for source-maps.

⬆️

版本与发布记录

@builder.io/sqlgenerate 共发布 9 个版本,首次发布于 2020/06/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.9latest2021/06/025 年前
1.2.82020/10/146 年前
1.2.8-0dev2020/09/026 年前
1.2.72020/06/246 年前
1.2.62020/06/246 年前
1.2.52020/06/246 年前

关于 @builder.io/sqlgenerate 的常见问题

@builder.io/sqlgenerate 是什么?

Generates SQL from a JSON AST.

如何安装 @builder.io/sqlgenerate?

在项目目录运行 npm install @builder.io/sqlgenerate,或使用 pnpm add / yarn add / bun add。

@builder.io/sqlgenerate 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/builder.io__sqlgenerate 是否存在。

@builder.io/sqlgenerate 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@builder.io/sqlgenerate 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=0.10.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@builder.io/sqlgenerate 可以商用吗?

@builder.io/sqlgenerate 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@builder.io/sqlgenerate 的下载量有多少?

根据 npm 官方下载统计,@builder.io/sqlgenerate 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,014 次,日均约 100 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@builder.io/sqlgenerate 还在维护吗?

最新版本 1.2.9 发布于 2021/06/02(5 年前);至今共发布 9 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/06/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。