npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sqlie

v0.0.5

Published

A simple Query builder working with NodeJS.

Downloads

48

Readme

Sqlie

简单的SQL语句构建工具。 A simple SQL query builder.

npm npm

内置简单模型,支持MySQL的联合主键。

Install

$ npm install sqlie --save

API

  • ModelBuilder 构建模型
  • createModel 构建模型
  • setQueryHandler 设置SQL语句执行函数
  • execute 执行SQL语句
  • DeleteBuilder 构建删除语句
  • InsertBuilder 构建插入数据语句
  • SelectBuilder 构建查询语句
  • JoinBuilder 构建JOIN表语句
  • JoinSelectBuilder 构建JOIN查询语句
  • UpdateBuilder 构建更新语句

Examples

SELECT

  1. A base SELECT:

    const {SelectBuilder} = require('sqlite');
       
    const builder = new SelectBuilder()
      .from('users')
      .select('name,age,address')
      .where('name', '=', 'Jon Snow')
      .where('age', '=', 22);
       
    builder.build();
    // => SELECT `name`, `age`, `address` FROM `users` WHERE `name` = 'Swat' AND `age` = 22
  2. SELECT with a simple JOIN:

    const {SelectBuilder} = require('sqlie');
       
    const builder = new SelectBuilder()
      .from('users', 'u') // alias 'u' for table 'users'
      .select('*') // optional with select all
      .where('name', '=', 'Jon Snow')
      .where('age', '=', 22)
      .join('hobbies', function(hobbyBuilder) {
        hobbyBuilder
          .setAlias('h')
          .select('hobby') // select 'hobby' from table 'hobbies'
          .onColumn('h.id', 'u.id');
      })
      .join('colors', function(colorBuilder) {
        colorBuilder
          .setAlias('c')
          .select('favorite') // select 'favorite' from table 'colors'
          .onColumn('c.user_id', 'u.id');
      });
       
    builder.build();
    // => SELECT `u`.*, `h`.`hobby`, `c`.favorite FROM `users`
    //    JOIN `hobbies` ON `h`.`id` = `u`.`id`
    //    JOIN `colors` ON `c`.`user_id` = `u`.`id`
    //    WHERE `u`.`name` = 'Jon Snow' AND `u`.`age` = 22
  3. INSERT

    const {InsertBuilder} = require('./dist');
       
    const builder = new InsertBuilder()
      .into('users')
      .set('name', 'Super Girl')
      .setSome({
        age: 18,
        gender: 'female'
      });
       
    builder.build();
    // => INSERT INTO `users` (`name`, `age`, `gender`) VALUES ('Super Girl', 18, 'female')
  4. UPDATE

    const {UpdateBuilder} = require('./dist');
       
    const builder = new UpdateBuilder()
      .from('users')
      .set('age', 22)
      .setSome({})
      .where('name', '=', 'Super Girl');
       
    builder.build();
    // => UPDATE `users` SET `age` = 22 WHERE `name` = 'Super Girl'
  5. 设置SQL执行函数

    const {createConnection} = require('mysql')
    const {setQueryHandler, execute} = require('sqlie')
    const connection =  createConnection({/*db config*/});
    // 设置 MySQL 语句执行函数
    setQueryHandler(connection.query.bind(connection));
    // 下面可以调用 execute 函数执行 SQL 语句了
    execute('SELECT * FROM tableName').then(function ({rows, fields}) {
        console.log(rows); // 查询结果
        console.log(fields);// 相关字段信息(不一定有结果) 
    })
  6. 模型

    const {createModel} = require('sqlie');
    const user = createModel('my_users', 'uid');
       
    // 联合主键 'gid'、'uid'
    const msg = createModel('im_group_msgs', ['gid', 'uid']);

TODO

  • [ ] 完善测试用例
  • [ ] 编写开发文档

Licence

MIT © Frge [email protected]