From 84078067dcf3e58221523fcde15417a163d73cae Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Mon, 27 Mar 2017 20:07:52 +0100 Subject: [PATCH] feat: distinguish between different connectiont types --- src/index.js | 17 ++++++++++------- src/types.js | 9 +++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index eb6d8201..38494829 100644 --- a/src/index.js +++ b/src/index.js @@ -13,16 +13,19 @@ import { NotFoundError } from './errors'; import type { - InternalQueryInsertType, + DatabasePoolConnectionType, + DatabaseSingleConnectionType, InternalQueryAnyType, - InternalQueryOneType, + InternalQueryInsertType, InternalQueryManyType, - InternalQueryType, - DatabaseConnectionType + InternalQueryOneType, + InternalQueryType } from './types'; export type { - DatabaseConnectionType + DatabaseConnectionType, + DatabasePoolConnectionType, + DatabaseSingleConnectionType } from './types'; export { @@ -114,7 +117,7 @@ export const any: InternalQueryAnyType = async (connection, sql, values) => { }; // eslint-disable-next-line flowtype/no-weak-types -const createConnection = async (configuration: Object): Promise => { +const createConnection = async (configuration: Object): Promise => { const connection = await createConnection2(configuration); return { @@ -130,7 +133,7 @@ const createConnection = async (configuration: Object): Promise { +const createPool = (configuration: Object): DatabasePoolConnectionType => { const pool = createPool2(configuration); return { diff --git a/src/types.js b/src/types.js index f3a2fa6f..0ad1f0f1 100644 --- a/src/types.js +++ b/src/types.js @@ -5,13 +5,18 @@ // eslint-disable-next-line flowtype/no-weak-types type InternalDatabaseConnectionType = any; -export type DatabaseConnectionType = {| +export type DatabaseSingleConnectionType = { + end: () => Promise +} & DatabaseConnectionType; +export type DatabasePoolConnectionType = DatabaseConnectionType; + +export type DatabaseConnectionType = { +any: QueryAnyType, +insert: QueryInsertType, +many: QueryManyType, +one: QueryOneType, +query: QueryType -|}; +}; type QueryPointResultType = {| +x: number,