未加星标

MySQL Connector/Node.JS 1.0.4 now on npmjs.com

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二03 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

mysql Connector/Node.JS 1.0.4 was recently released as a development milestone release. This is the first version available via npmjs.com . npmjs.com is the central registry for Node.JS packages. This and potential future official MySQL packages can be found using the @mysql organisation. For this to work we had to change the package name to contain that prefix and have chosen the name @mysql/xdevapi as this package provides the implementation of our X DevAPI for Node.JS and we have a free namespace for potential future libraries as part of our Connector/Node.JS product.


MySQL Connector/Node.JS 1.0.4 now on npmjs.com

Given an existing Node.JS project we can easily install the library:

$ npminstall --save @mysql/xdevapi [email protected] /home/johannes/experiments/myapp └── @[email protected]

As presented with previous releases the implementation is built around Promises. After the installation it’s easy to ask for a session:

const xdevapi = require([email protected]/xdevapi'); const promise = xdevapi.getSession({ host: 'localhost', port: 33060, dbUser: 'username', dbPassword: 'veryverysecret' });

If the MySQL Server is running and the X Plugin was loaded this Promise object will resolve to a session, else it will be rejected.

As a new feature in 1.0.4 the connection parameters can also be provided in form of an URL. As the URL is defined in the X DevAPI it can be shared among applications using different languages and MySQL Connectors:

const xdevapi = require([email protected]/xdevapi'); const promise = xdevapi.getSession('mysqlx://username:[email protected]');

Another new feature in MySQL Connector/Node.JS is support for view DDL operations. To create a view a CRUD select object can be used:

const myschema = session.getSchema('myschema'); const table = myschema.getTable('a_table'); const selection = table.select(['id', 'CONCAT(field1, field2)']).where('1 = 2'); const viewDefinition = myschema.createView('a_view'); const promise = viewDefinition.definedAs(selection).security(viewDefinition.INVOKER).execute();

In case the view isn’t needed anymore it can of course be dropped again:

const promise = session.getSchema('myschema').dropView('a_view');

For information purpose another addition are functions to gather row or document counts from tables or collections:

const promise1 = myschema.getTable('a_table').count(); const promise2 = myschema.getCollection('a_collection').count();

For the future there’s more to come. We’re working on different improvements to the API and performance. More on this in a later post.

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: SQLMySQLSQL Server
分页:12
转载请注明
本文标题:MySQL Connector/Node.JS 1.0.4 now on npmjs.com
本站链接:http://www.codesec.net/view/484555.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(30)