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

pr-easy-db

v1.0.4

Published

快速生成SQL语句

Downloads

297

Readme

快速生成 SQL 语句。

立即开始

安装

npm i pr-easy-db

引入


import { PrEasyD1 } from 'pr-easy-db'

// 定义你数据库的所有表名
type TableNames = 'Users' | 'Books'

// 将你的表名注入 以便代码直接索引提示
const prEasyD1 = new PrEasyD1<TableNames>()

增加

INSERT INTO Users (_id, username, age) VALUES (?, ?, ?)
{
  const sql = prEasyD1.table('Users').insert([{ _id: 123, username: 'breathe', age: 12 }])
  const { query, values } = sql.end()
  console.log('\x1b[38;2;0;151;255m%c%s\x1b[0m', 'color:#0097ff;padding:16px 0;', `------->Breathe:{ query, values }`, { query, values })
}

查询

SELECT * FROM Users WHERE ((age = ?) AND ((account LIKE ? OR mobile LIKE ? OR emali LIKE ?)) AND (state = ?)) LIMIT ?, ?
{
  const account = 'breathe' // 手机号 | 邮箱 | 账号
  // 多条件查询
  const pipelineItem = {
    $match: { age: 12, $or: [{ account: account, mobile: account, emali: account }], state: 1 },
    page: 1,
    size: 20
  }
  const sql = prEasyD1.table('Users').select(pipelineItem)
  const { query, values } = sql.end()
  console.log('\x1b[38;2;0;151;255m%c%s\x1b[0m', 'color:#0097ff;padding:16px 0;', `------->Breathe:{ query, values }`, { query, values })
}

// 如果你只想查询总数
{
  const { query, values } = sql.total()
  console.log('\x1b[38;2;0;151;255m%c%s\x1b[0m', 'color:#0097ff;padding:16px 0;', `------->Breathe:{ query, values }`, { query, values })
}

修改

UPDATE Users SET name = ?, age = ? WHERE (_id = ?)
{
  const sql = prEasyD1.table('Users').update({ _id: 123, name: 'aaaa', age: 44 }, '_id')
  const { query, values } = sql.end()
  console.log('\x1b[38;2;0;151;255m%c%s\x1b[0m', 'color:#0097ff;padding:16px 0;', `------->Breathe:{ query, values }`, { query, values })
}

删除

DELETE FROM Users WHERE _id IN (?, ?)
{
  const ids = ['123', '456']
  const sql = prEasyD1.table('Users').delete(ids, '_id')
  const { query, values } = sql.end()
  console.log('\x1b[38;2;0;151;255m%c%s\x1b[0m', 'color:#0097ff;padding:16px 0;', `------->Breathe:{ query, values }`, { query, values })
}

代码仓库

github

贡献

breathe