Skip to content

Commit

Permalink
Using pool instead of db
Browse files Browse the repository at this point in the history
  • Loading branch information
pomgui committed Sep 5, 2020
1 parent b67b6a5 commit 7fb2c2a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
11 changes: 5 additions & 6 deletions lib/service/PiService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Request, Response, Router, IRouterMatcher, Application } from "express";
import { PiDbPoolFactoryFn, PiServiceOptions, PiExceptionHandlerParams } from "./types";
import { PiServiceOptions, PiExceptionHandlerParams } from "./types";
import { PiTypeDescriptor } from '@pomgui/rest-lib';
import { PiDatabasePool, PiDatabase } from '@pomgui/database';

var
_router: Router = Router(),
_dbPool: PiDatabasePool | null;
_dbPool: PiDatabasePool | undefined;

export function PiGET(path: string, options?: PiServiceOptions) { return decorator(path, _router.get, options) }
export function PiPOST(path: string, options?: PiServiceOptions) { return decorator(path, _router.post, options) }
Expand Down Expand Up @@ -77,9 +77,8 @@ function decorator(path: string, defineRoute: IRouterMatcher<void>, options?: Pi
}
}

export function PiService(config: { services: { new(): any }[], dbPoolFactoryFn?: PiDbPoolFactoryFn }): Router {
config.services.forEach(s => new s()); // Create an instance, just to access to the decorators
if (config.dbPoolFactoryFn)
_dbPool = config.dbPoolFactoryFn();
export function PiService(config: { servicesList: { new(): any }[], dbPool?: PiDatabasePool }): Router {
config.servicesList.forEach(s => new s()); // Create an instance, just to access to the decorators
_dbPool = config.dbPool;
return _router;
}
5 changes: 0 additions & 5 deletions lib/service/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import { PiDatabase, PiDatabasePool } from "@pomgui/database"
import { Request, Response } from "express"
import { PiDescriptor } from '@pomgui/rest-lib'

/**
* Signature of the database factory function
*/
export type PiDbPoolFactoryFn = { (): PiDatabasePool | null; }

export type PiServiceOptions = {
customSend?: boolean;
database?: boolean;
Expand Down

0 comments on commit 7fb2c2a

Please sign in to comment.