From bd999bfe3ef96da2afc9bba726480a2ceca523e5 Mon Sep 17 00:00:00 2001 From: biniam Date: Thu, 6 Jul 2017 17:35:42 -0400 Subject: [PATCH] fixup! apply review comments --- .../controllers/AccountController.ts | 6 +- services/account-without-juggler/package.json | 4 +- .../account/datasources/mysql.json | 4 +- .../account/datasources/mysqlconn.ts | 89 ++++++++++--------- services/todo-legacy/package.json | 1 - 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/services/account-without-juggler/controllers/AccountController.ts b/services/account-without-juggler/controllers/AccountController.ts index 7ba5e21..3c841da 100644 --- a/services/account-without-juggler/controllers/AccountController.ts +++ b/services/account-without-juggler/controllers/AccountController.ts @@ -5,9 +5,9 @@ import { inject } from 'loopback-next/packages/context'; @api(def) export class AccountController { - @inject('repositories.account') private repository: accountRepository; - - constructor() {} + constructor( + @inject('repositories.account') private repository: accountRepository + ) {} //fixme figure out how to use Filter interface //fixme filter is string even though swagger spec diff --git a/services/account-without-juggler/package.json b/services/account-without-juggler/package.json index 119f1c4..b75610d 100644 --- a/services/account-without-juggler/package.json +++ b/services/account-without-juggler/package.json @@ -5,8 +5,8 @@ "main": "index.ts", "dependencies": { "@types/mysql": "0.0.34", - "mysql-promise": "^4.1.0", - "mysql2": "^1.3.5" + "mysql": "^2.13.0", + "mysql-promise": "^4.1.0" }, "devDependencies": { "@loopback/testlab": "^4.0.0-alpha.5", diff --git a/services/account-without-juggler/repositories/account/datasources/mysql.json b/services/account-without-juggler/repositories/account/datasources/mysql.json index d10e6ae..a6ecfb9 100644 --- a/services/account-without-juggler/repositories/account/datasources/mysql.json +++ b/services/account-without-juggler/repositories/account/datasources/mysql.json @@ -1,7 +1,7 @@ { "host":"localhost", "user":"root", - "password": "dis-mysql", - "database": "test-db", + "password": "password", + "database": "account-service", "port": 3306 } diff --git a/services/account-without-juggler/repositories/account/datasources/mysqlconn.ts b/services/account-without-juggler/repositories/account/datasources/mysqlconn.ts index 3672c85..5f2eac6 100644 --- a/services/account-without-juggler/repositories/account/datasources/mysqlconn.ts +++ b/services/account-without-juggler/repositories/account/datasources/mysqlconn.ts @@ -1,8 +1,8 @@ -const debug = require("debug")("account-without-juggler"); -const mysql = require("mysql"); -const db = require("mysql-promise")(); -import { CrudConnector } from "loopback-next/packages/repository/src/crud-connector"; -import { IError } from "@types/mysql"; +const debug = require('debug')('loopback:repositories:account:datasources:connections:mysql'); +const mysql = require('mysql'); +const db = require('mysql-promise')(); +import { CrudConnector } from 'loopback-next/packages/repository/src/crud-connector'; +import { IError, IConnection } from '@types/mysql'; import { Class, DataSource, @@ -12,37 +12,38 @@ import { ObjectType, Options, Where -} from "loopback-next/packages/repository"; +} from 'loopback-next/packages/repository'; export class MySqlConn implements CrudConnector { - private connection: any; + //fixme make connection strongly typed + private connection: any constructor(config: Object) { - db.configure(config, require("mysql2")); + db.configure(config, mysql); this.connection = db; } - name: "mysql"; + name: 'mysql'; interfaces?: string[]; - connect() { + connect(): Promise { return this.connection.connect(); } - disconnect() { + disconnect(): Promise { return this.connection.end(); } - ping() { + ping(): Promise { return this.connection.ping(); } - public updateAll( + updateAll( modelClass: Class, data: EntityData, where: Where, options: Options ): Promise { - throw new Error("Not implemented yet."); + throw new Error('Not implemented yet.'); } - public create( + create( modelClass: Class, entity: EntityData, options: Options @@ -52,81 +53,81 @@ export class MySqlConn implements CrudConnector { for (var prop in modelClass.definition.properties) { placeHolders.push('?'); } - let createQuery = "INSERT INTO ?? VALUES (" + placeHolders.join(',') + ")"; + let createQuery = 'INSERT INTO ?? VALUES (' + placeHolders.join(',') + ')'; var vals = [modelClass.modelName]; for (var prop in entity) { vals.push(entity[prop]); } let sqlStmt = mysql.format(createQuery, vals); - debug("insert stmt ", sqlStmt); + debug('insert stmt ', sqlStmt); return self.connection.query(sqlStmt).spread(function(result: any) { return result.affectedRows; }); } - public save( + save( modelClass: Class, entity: EntityData, options: Options ): Promise { - throw new Error("Not implemented yet."); + throw new Error('Not implemented yet.'); } - public find( + find( modelClass: Class, filter: Filter, options: Options ): Promise { let self = this; - let findQuery = "SELECT * FROM ?? "; + let findQuery = 'SELECT * FROM ?? '; findQuery = mysql.format(findQuery, [modelClass.modelName]); if (filter.where) { - let whereClause = "?? = ?"; + let whereClause = '?? = ?'; for (var key in filter.where) { whereClause = mysql.format(whereClause, [key, filter.where[key]]); } - findQuery += " WHERE " + whereClause; + findQuery += ' WHERE ' + whereClause; } - debug("Find ", findQuery); + debug('Find ', findQuery); return self.connection.query(findQuery).spread(function(rows: any) { return rows; }); } - public findById( + findById( modelClass: Class, id: Number, options: Options ): Promise { - throw new Error("Not implemented yet."); + throw new Error('Not implemented yet.'); } - public update( + update( modelClass: Class, entity: EntityData, options: Options ): Promise { - throw new Error("Not implemented yet."); + throw new Error('Not implemented yet.'); } - public delete( + delete( modelClass: Class, entity: EntityData, options: Options ): Promise { - throw new Error("Not implemented yet."); + throw new Error('Not implemented yet.'); } - public createAll( + createAll( modelClass: Class, entities: EntityData[], options: Options ): Promise { - throw new Error("Not implemented yet."); + throw new Error('Not implemented yet.'); } - public updateById( + updateById( modelClass: Class, id: Number, data: EntityData, @@ -143,30 +144,30 @@ export class MySqlConn implements CrudConnector { let whereClause = mysql.format(' WHERE ??=?', ['id', id]); updateQuery += whereClause; - debug("updateById ", updateQuery); + debug('updateById ', updateQuery); return self.connection.query(updateQuery).spread(function(result: any) { return result.affectedRows; }); } - public replaceById( + replaceById( modelClass: Class, id: Number, data: EntityData, options: Options ): Promise { - throw new Error("Not implemented yet."); + throw new Error('Not implemented yet.'); } - public deleteAll( + deleteAll( modelClass: Class, where: Where, options: Options ): Promise { - throw new Error("Not implemented yet."); + throw new Error('Not implemented yet.'); } - public deleteById( + deleteById( modelClass: Class, id: Number, options: Options @@ -177,25 +178,25 @@ export class MySqlConn implements CrudConnector { let whereClause = mysql.format(' WHERE ??=?', ['id', id]); deleteQuery += whereClause; - debug("deleteById ", deleteQuery); + debug('deleteById ', deleteQuery); return self.connection.query(deleteQuery).spread(function(result: any) { return result.affectedRows; }); } - public count( + count( modelClass: Class, where: Where, options: Options ): Promise { - throw new Error("Not implemented yet."); + throw new Error('Not implemented yet.'); } - public exists( + exists( modelClass: Class, id: Number, options: Options ): Promise { - throw new Error("Not implemented yet."); + throw new Error('Not implemented yet.'); } } diff --git a/services/todo-legacy/package.json b/services/todo-legacy/package.json index f7ab763..05a9840 100644 --- a/services/todo-legacy/package.json +++ b/services/todo-legacy/package.json @@ -15,7 +15,6 @@ }, "devDependencies": { "@loopback/testlab": "^4.0.0-alpha.2", - "@types/mocha": "^2.2.41", "mocha": "^3.3.0" }, "dependencies": {