@@ -18,7 +18,7 @@ function init(cfg) {
1818 return co ( function * gen ( ) {
1919 console . log ( 'Connecting to the database uri=%s' , conString ) ;
2020 const connection = new cosql . Connection ( conString ) ;
21- // Always attach an error listener
21+ // Always attach an error listener
2222 connection . on ( 'error' , ( err ) => this . emit ( 'error' , err ) ) ;
2323 let sql = cfg . query ;
2424 yield connection . connect ( ) ;
@@ -27,7 +27,7 @@ function init(cfg) {
2727 console . log ( 'Found following prepared variable:type pairs=%j' , vars ) ;
2828 pstmt = new cosql . PreparedStatement ( connection ) ;
2929 for ( const tuple of vars ) {
30- const [ placeholder , type ] = tuple . split ( ':' ) ;
30+ const [ placeholder , type ] = tuple . split ( ':' ) ;
3131 const name = placeholder . substr ( 1 ) ;
3232 switch ( type ) {
3333 case 'string' :
@@ -48,8 +48,8 @@ function init(cfg) {
4848 default :
4949 console . log ( 'WARNING: Can figure out the type key=%s type=%s' , name , type ) ;
5050 }
51- // Now let's remove all :string :boolean :date etc to the name only
52- sql = sql . replace ( tuple , placeholder ) ;
51+ // Now let's remove all :string :boolean :date etc to the name only
52+ sql = sql . replace ( tuple , placeholder ) ;
5353 }
5454 console . log ( 'Resulting SQL=%s' , sql ) ;
5555 yield pstmt . prepare ( sql ) ;
@@ -62,37 +62,35 @@ function init(cfg) {
6262 *
6363 * @param cfg
6464 */
65- function getMetaModel ( cfg ) {
66- return co ( function * gen ( ) {
65+ function getMetaModel ( cfg , cb ) {
6766 const sql = cfg . query ;
6867 const result = {
69- in : {
70- type : 'object' ,
71- properties : { }
72- } ,
73- out : { }
68+ in : {
69+ type : 'object' ,
70+ properties : { }
71+ } ,
72+ out : { }
7473 } ;
7574 if ( sql && sql . length > 0 ) {
76- const vars = sql . match ( VARS_REGEXP ) ;
77- const fields = result . in . properties ;
78- for ( const tuple of vars ) {
79- const [ key , type ] = tuple . split ( ':' ) ;
80- let jsType = 'string' ;
81- switch ( type ) {
82- case 'date' :
83- jsType = 'string' ;
84- break ;
85- case 'bigint' :
86- jsType = 'number' ;
87- break ;
75+ const vars = sql . match ( VARS_REGEXP ) ;
76+ const fields = result . in . properties ;
77+ for ( const tuple of vars ) {
78+ const [ key , type ] = tuple . split ( ':' ) ;
79+ let jsType = 'string' ;
80+ switch ( type ) {
81+ case 'date' :
82+ jsType = 'string' ;
83+ break ;
84+ case 'bigint' :
85+ jsType = 'number' ;
86+ break ;
87+ }
88+ fields [ key . substr ( 1 ) ] = {
89+ type : jsType
90+ } ;
8891 }
89- fields [ key . substr ( 1 ) ] = {
90- type : jsType
91- } ;
92- }
9392 }
94- return result ;
95- } ) ;
93+ cb ( null , result ) ;
9694}
9795
9896/**
0 commit comments