Skip to content

Commit

Permalink
fixup! apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
biniam committed Jul 6, 2017
1 parent 19964a3 commit bd999bf
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions services/account-without-juggler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"host":"localhost",
"user":"root",
"password": "dis-mysql",
"database": "test-db",
"password": "password",
"database": "account-service",
"port": 3306
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<void> {
return this.connection.connect();
}
disconnect() {
disconnect(): Promise<void> {
return this.connection.end();
}
ping() {
ping(): Promise<void> {
return this.connection.ping();
}

public updateAll(
updateAll(
modelClass: Class<Entity>,
data: EntityData,
where: Where,
options: Options
): Promise<number> {
throw new Error("Not implemented yet.");
throw new Error('Not implemented yet.');
}

public create(
create(
modelClass: Class<Entity>,
entity: EntityData,
options: Options
Expand All @@ -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>,
entity: EntityData,
options: Options
): Promise<EntityData> {
throw new Error("Not implemented yet.");
throw new Error('Not implemented yet.');
}

public find(
find(
modelClass: Class<Entity>,
filter: Filter,
options: Options
): Promise<EntityData[]> {
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<Entity>,
id: Number,
options: Options
): Promise<EntityData> {
throw new Error("Not implemented yet.");
throw new Error('Not implemented yet.');
}

public update(
update(
modelClass: Class<Entity>,
entity: EntityData,
options: Options
): Promise<boolean> {
throw new Error("Not implemented yet.");
throw new Error('Not implemented yet.');
}

public delete(
delete(
modelClass: Class<Entity>,
entity: EntityData,
options: Options
): Promise<boolean> {
throw new Error("Not implemented yet.");
throw new Error('Not implemented yet.');
}

public createAll(
createAll(
modelClass: Class<Entity>,
entities: EntityData[],
options: Options
): Promise<EntityData[]> {
throw new Error("Not implemented yet.");
throw new Error('Not implemented yet.');
}

public updateById(
updateById(
modelClass: Class<Entity>,
id: Number,
data: EntityData,
Expand All @@ -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<Entity>,
id: Number,
data: EntityData,
options: Options
): Promise<boolean> {
throw new Error("Not implemented yet.");
throw new Error('Not implemented yet.');
}

public deleteAll(
deleteAll(
modelClass: Class<Entity>,
where: Where,
options: Options
): Promise<number> {
throw new Error("Not implemented yet.");
throw new Error('Not implemented yet.');
}

public deleteById(
deleteById(
modelClass: Class<Entity>,
id: Number,
options: Options
Expand All @@ -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<Entity>,
where: Where,
options: Options
): Promise<number> {
throw new Error("Not implemented yet.");
throw new Error('Not implemented yet.');
}

public exists(
exists(
modelClass: Class<Entity>,
id: Number,
options: Options
): Promise<boolean> {
throw new Error("Not implemented yet.");
throw new Error('Not implemented yet.');
}
}
1 change: 0 additions & 1 deletion services/todo-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
},
"devDependencies": {
"@loopback/testlab": "^4.0.0-alpha.2",
"@types/mocha": "^2.2.41",
"mocha": "^3.3.0"
},
"dependencies": {
Expand Down

0 comments on commit bd999bf

Please sign in to comment.