刚发现MySQL发布了Node的Connector
找java的connector时无意间发现的,一看文档发布日期竟然一个月前就有了 下载地址https://dev.mysql.com/downloads/connector/nodejs/ 文档https://dev.mysql.com/doc/dev/connector-nodejs/
版本要求
Node.js 4.2.x
MySQL 5.7.19 (挺新的版本了,大多数人应该都要重新下一个,顺便附上下载地址https://dev.mysql.com/downloads/mysql/)
先安装了再说 npm install @mysql/xdevapi
官方给的示例代码
const mysql = require('@mysql/xdevapi');
mysql
.getSession({
host: 'localhost',
port: 33060,
dbUser: 'user',
dbPassword: 'passwd'
})
.then(session => {
console.log('Session created');
return session.createSchema('test_schema');
})
.then(schema => {
console.log('Schema created');
return schema.createCollection('myCollection');
})
.then(collection => {
console.log('Collection created')
return Promise.all([
collection
.add({ baz: { foo: 'bar' } }, { foo: { bar: 'baz' } })
.execute(),
collection
.find("$.baz.foo == 'bar'")
.execute(row => {
console.log('Found row: %j', row);
})
.then(res => {
console.log('Collection find finished');
}),
collection
.remove("($.foo.bar) == 'baz'")
.execute()
.then(() => {
console.log('Document deleted');
}),
collection
.drop()
.then(() => {
console.log('Collection deleted');
})
]);
})
.then(() => {
return session.dropSchema('test_schema');
})
.then(() => {
console.log('Schema deleted');
return session.close();
})
.then(() => {
console.log('Session destroyed');
})
.catch(err => {
console.log(err.stack);
});
看起来相当不错,可以去尝试一下了
1 回复
这文档不走心啊,也没开源
{ modified: '2017-09-28T09:52:10.360Z',
created: '2016-10-10T17:44:40.541Z',
'1.0.4': '2016-10-10T17:44:40.541Z',
'1.0.5': '2016-11-14T11:48:40.114Z',
'1.0.6': '2017-03-07T09:50:02.519Z',
'8.0.7': '2017-07-10T11:18:09.590Z',
'8.0.8': '2017-09-28T09:52:10.360Z' },
```