
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
It is written in JavaScript,crud for node.js.You can also use transactions very easily.
mysqls是在node.js场景中使用mysql,根据传入的参数生成相应的sql语句。 插件本身只负责生成sql语句,不执行任何的增删改查,增删改查交给mysql。
API参考很流行的ThinkPHP模型API,因为它已经做够流行和好用了。非常感谢ThinkPHP文档,很多案例参考其文档
npm install mysqls --save-dev
execute :执行单挑sql语句 参数:(config,sqlStr)
sql :链式调用生成sql语句 链式调用语法,参考后文
transaction :执行事务相关任务时使用 参数:(config,sqlArr)
//import方式
import { execute,sql,transaction } from 'mysqls'
//require方式
let { execute,sql,transaction } = require('mysqls')
let config={
host:'localhost',
user:'root',
password:'123456',
database:'web-performance',
port:'3306',
}
//使用
let sqlstr = sql.table('web_pages').where({id:147}).select()
execute(config,sqlstr).then(res=>{
console.log(res)
}).catch(err=>{
console.log(err)
})
let sqlstr = sql.table('web_pages').where({id:147}).select()
let result = await execute(config,sqlstr)
console.log(result)
let tranSqlArr = [
sql.table('table1').data({number:number-5}).update(),
sql.table('table2').data({number:number+5}).update()
]
let result = await transaction(config,tranSqlArr)
console.log(result)
备注:sql调用方法的顺序内部已经做了排序,因此可以不按严格的sql语句顺序来写 查询
sql
.table('node_table')
.field('id,name')
.where({id:1})
.select()
SELECT id,name FROM node_table WHERE id=1
插入
sql
.table('node_table')
.data({name:'zane',email:'752636052@qq.com'})
.insert()
INSERT INTO node_table (name,email) VALUES (`zane`,`752636052@qq.com`)
更新
sql
.table('node_table')
.data({name:'zane',email:'752636052@qq.com'})
.update()
UPDATE node_table SET name=`zane`,email=`752636052@qq.com`
删除
sql .table('node_table')
.where({name:'zane'})
.delet();
DELETE FROM node_table WHERE name=`zane`
//参数json多字段
sql
.table('node_table')
.where({id:1,name:'zane'})
.select()
SELECT * FROM node_table WHERE id=1 AND name=`zane`
//参数数组
let data=[
{id:1,name:'zhangsan',_type:'or'},
{sex:1,number:3}
]
sql.table('node_table').where(data).select()
SELECT * FROM node_table WHERE (id=1 OR name=`zhangsan` ) AND (sex=1 AND number=3 )
//多字段连接方式
let data=[
{id:1,name:'zhangsan',_type:'or',_nexttype:'or'},
{sex:1,number:3,_type:'and'}
]
sql.table('node_table').where(data).select()
SELECT * FROM node_table WHERE (id=1 OR name=`zhangsan`) OR (sex=1 AND number=3)
//表达式查询
let data={
id:{eq:100,egt:10,_type:'or'},
name:'zhangshan'
}
sql.table('node_table').where(data).select()
SELECT * FROM node_table WHERE ((id=100) OR (id>=10)) AND name=`zhangshan`
//混合查询
let data=[{
id:{eq:100,egt:10,_type:'or'},
name:'zhangshan',
_nexttype:'or'
},{
status:1,
name:{like:'%zane%'}
}]
sql.table('node_table').where(data).select()
SELECT * FROM node_table WHERE (((id=100) OR (id>=10)) AND name=`zhangshan`) OR (status=1 AND ((name LIKE `%zane%`)))
//UNION , UNION ALL 组合使用
sql
.union('SELECT * FROM think_user_1',true)
.union('SELECT * FROM think_user_2',true)
.union(['SELECT * FROM think_user_3','SELECT name FROM think_user_4'])
.union('SELECT * FROM think_user_5',true)
.select()
得到
(SELECT * FROM think_user_1) UNION ALL
(SELECT * FROM think_user_2) UNION ALL
(SELECT * FROM think_user_3) UNION
(SELECT name FROM think_user_4) UNION
(SELECT * FROM think_user_5)
更多用法请查看详细文档
git clone https://github.com/wangweianger/mysqls.git
npm install
//dve
npm run dve
//product
npm run build
FAQs
# mysqls It is written in JavaScript. crud for mysql. You can also use transactions very easily.
The npm package mysqls receives a total of 14 weekly downloads. As such, mysqls popularity was classified as not popular.
We found that mysqls demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.