1- /**
2- * Copyright(c) ali-sdk and other contributors.
3- * MIT Licensed
4- *
5- * Authors:
6- * fengmk2 <m@fengmk2.com> (http://fengmk2.com)
7- */
8-
91'use strict' ;
102
113/**
@@ -16,7 +8,7 @@ const assert = require('assert');
168const rds = require ( '../' ) ;
179const config = require ( './config' ) ;
1810
19- describe ( 'test/ client.test.js' , function ( ) {
11+ describe ( 'client.test.js' , function ( ) {
2012 const prefix = 'prefix-' + process . version + '-' ;
2113 const table = 'ali-sdk-test-user' ;
2214 before ( function * ( ) {
@@ -38,6 +30,13 @@ describe('test/client.test.js', function () {
3830 assert ( rows ) ;
3931 assert ( Array . isArray ( rows ) ) ;
4032 } ) ;
33+
34+ it ( 'should connection query one row' , function * ( ) {
35+ let conn = yield this . db . getConnection ( ) ;
36+ let row = yield conn . queryOne ( 'show tables' ) ;
37+ conn . release ( ) ;
38+ assert ( row ) ;
39+ } ) ;
4140 } ) ;
4241
4342 describe ( 'escape()' , function ( ) {
@@ -52,7 +51,7 @@ describe('test/client.test.js', function () {
5251 } ) ;
5352 } ) ;
5453
55- describe ( 'query()' , function ( ) {
54+ describe ( 'query(), queryOne() ' , function ( ) {
5655 before ( function * ( ) {
5756 yield this . db . query ( 'insert into ??(name, email, gmt_create, gmt_modified) \
5857 values(?, ?, now(), now())' ,
@@ -69,6 +68,12 @@ describe('test/client.test.js', function () {
6968 assert . equal ( rows [ 0 ] . name , prefix + 'fengmk2' ) ;
7069 assert . equal ( rows [ 1 ] . name , prefix + 'fengmk3' ) ;
7170 } ) ;
71+
72+ it ( 'should select 1 row' , function * ( ) {
73+ const row = yield this . db . queryOne ( 'select * from ?? where email=? order by id' ,
74+ [ table , prefix + 'm@fengmk2.com' ] ) ;
75+ assert . equal ( row . name , prefix + 'fengmk2' ) ;
76+ } ) ;
7277 } ) ;
7378
7479 describe ( 'transactions' , function ( ) {
@@ -323,6 +328,11 @@ describe('test/client.test.js', function () {
323328 values(?, ?, now(), now())' ,
324329 [ table , prefix + 'beginTransactionScopeCtx2' , prefix + 'm@beginTransactionScopeCtx1.com' ] ) ;
325330
331+ // test query one
332+ const row = yield conn . queryOne ( 'select * from ?? where name=?' , [ table , prefix + 'beginTransactionScopeCtx1' ] ) ;
333+ assert ( row ) ;
334+ assert . equal ( row . name , prefix + 'beginTransactionScopeCtx1' ) ;
335+
326336 const fooResult = yield fooInsert ( ) ;
327337 assert . equal ( fooResult , true ) ;
328338 const barResult = yield barInsert ( ) ;
0 commit comments