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

legible-db

v1.0.9

Published

基于egg-mysql 易用的链式数据库查询语句

Downloads

19

Readme

legible-db

基于egg-mysql 易用的链式数据库查询语句,因为egg原生的mysql使用上有很多不方便,受thinkphp链式数据库查询方式影响,因此做了类似封装。 在网上也找到另一个做了类似封装的,感觉使用起来没那么好用(地址如下):

 https://github.com/AspenLuoQiang/hyoga-mysql/

所以还是自己写了一套,有些不常用的暂时没做封装,有待完善。有需要的小伙伴欢迎联系qq:464223078

github地址:

https://github.com/kilet/legible-db/

1.函数可以作为mysql常用语句生成器在任意js语境下使用 // 例如

let result = Db.table('tbl_a')

.field('id,a,b')

.where({ id: 1 })

.where('b=3')

.where('c','not like','x')

.where({d:[5,6,7]},'not in')

.group('a')

.page(0,10)

.order('id')

.select()

生成语句:SELECT id,a,b FROM tbl_a where id=1 AND b=3 AND c not like '%x%' AND d not in (5,6,7) group by a order by id limit 0,10

更多详情 请参考test.js 运行测试代码:node test.js

2.在egg框架中使用最佳 需要初始化设置默认数据库:

安装:npm install legible-db

在app.js 调用:

Db.init const Db = require('legible-db');

module.exports = app => {

     // 其他代码...

     Db.init(app,'your dbname');

     // 其他代码...

};

设置后,

执行 Db.table('tbl_a').select(false) 返回生成的字符串

执行 await Db.table('tbl_a').select() 返回查询的数据

update,insert,delte类似

封装常用时间条件: whereTime() 参数 key:数据库表字段名 tm1:(1)可以是特殊字符串时【tm2:表示偏移量,缺省为0】,可以为'today','yesterday','tomorrow','week','month','year','lastWeek','lastMonth','lastYear' (2)可以是YYYY-MM-DD 的时间格式 (3)可以是时间戳值,【tm2:若tm2有值表示两个时间戳所指定的日期之间】