From 50a8d9810e89df1eef6bad893969fca3a0130d9f Mon Sep 17 00:00:00 2001 From: Brayden Wilmoth Date: Fri, 24 May 2024 20:50:48 -0400 Subject: [PATCH] Move QueryType to query-params --- jest.config.js | 4 ---- src/client.ts | 4 ++-- src/connections/cloudflare.ts | 3 ++- src/connections/index.ts | 15 ++------------- src/connections/outerbase.ts | 5 +++-- src/query-params.ts | 12 ++++++++++++ tests/connections/cloudflare.test.ts | 2 +- tests/connections/outerbase.test.ts | 2 +- 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/jest.config.js b/jest.config.js index 926beb5..a994f99 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,10 +4,6 @@ const { pathsToModuleNameMapper } = require('ts-jest') const { compilerOptions } = require('./tsconfig') pathsToModuleNameMapper(compilerOptions.paths, { prefix: '' }) -const moduleNameMapper = pathsToModuleNameMapper(compilerOptions.paths, { - prefix: '/', -}) -console.log(moduleNameMapper) module.exports = { preset: 'ts-jest', diff --git a/src/client.ts b/src/client.ts index 8a2ae04..1cbf054 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,6 +1,6 @@ -import { Connection, QueryType } from './connections' +import { Connection } from './connections' import { Query, constructRawQuery } from './query' -import { QueryParams } from './query-params' +import { QueryParams, QueryType } from './query-params' interface QueryBuilder { action: 'select' | 'insert' | 'update' | 'delete' diff --git a/src/connections/cloudflare.ts b/src/connections/cloudflare.ts index cd17022..fe67ae7 100644 --- a/src/connections/cloudflare.ts +++ b/src/connections/cloudflare.ts @@ -1,5 +1,6 @@ +import { QueryType } from 'src/query-params' import { Query, constructRawQuery } from '../query' -import { Connection, QueryType } from './index' +import { Connection } from './index' export class CloudflareD1Connection implements Connection { // The Cloudflare API key with D1 access diff --git a/src/connections/index.ts b/src/connections/index.ts index a8eb25d..4351a0b 100644 --- a/src/connections/index.ts +++ b/src/connections/index.ts @@ -1,19 +1,8 @@ +import { QueryType } from 'src/query-params' import { Query } from '../query' -/** - * Database queries are constructed either by named or positional parameters. - * Named parameters are used to identify the parameter by name in the query - * and are replaced by the value of the parameter. Positional parameters are - * used to identify the parameter by position in the query and are replaced - * by the value of the parameter. - */ -export enum QueryType { - named = 'named', - positional = 'positional', -} - export interface Connection { - queryType?: QueryType + queryType: QueryType connect: (details: Record) => Promise disconnect: () => Promise diff --git a/src/connections/outerbase.ts b/src/connections/outerbase.ts index a01af0f..59d5322 100644 --- a/src/connections/outerbase.ts +++ b/src/connections/outerbase.ts @@ -1,12 +1,13 @@ +import { QueryType } from 'src/query-params' import { Query, constructRawQuery } from '../query' -import { QueryParamsNamed } from '../query-params' -import { Connection, QueryType } from './index' +import { Connection } from './index' export const API_URL = 'https://app.outerbase.com' export class OuterbaseConnection implements Connection { // The API key used for Outerbase authentication api_key: string | undefined + // Default query type to named for Outerbase queryType = QueryType.named /** diff --git a/src/query-params.ts b/src/query-params.ts index 13c0594..a3e59e6 100644 --- a/src/query-params.ts +++ b/src/query-params.ts @@ -1,3 +1,15 @@ +/** + * Database queries are constructed either by named or positional parameters. + * Named parameters are used to identify the parameter by name in the query + * and are replaced by the value of the parameter. Positional parameters are + * used to identify the parameter by position in the query and are replaced + * by the value of the parameter. + */ +export enum QueryType { + named = 'named', + positional = 'positional', +} + export type QueryParamsNamed = Record export type QueryParamsPositional = any[] export type QueryParams = QueryParamsNamed | QueryParamsPositional diff --git a/tests/connections/cloudflare.test.ts b/tests/connections/cloudflare.test.ts index a1c6125..74d9249 100644 --- a/tests/connections/cloudflare.test.ts +++ b/tests/connections/cloudflare.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test } from '@jest/globals' import { CloudflareD1Connection } from 'src/connections/cloudflare' -import { QueryType } from 'src/index' +import { QueryType } from 'src/query-params' describe('CloudflareD1Connection', () => { describe('Query Type', () => { diff --git a/tests/connections/outerbase.test.ts b/tests/connections/outerbase.test.ts index ec142b4..83205e0 100644 --- a/tests/connections/outerbase.test.ts +++ b/tests/connections/outerbase.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test } from '@jest/globals' import { OuterbaseConnection } from 'src/connections/outerbase' -import { QueryType } from 'src/index' +import { QueryType } from 'src/query-params' describe('OuterbaseConnection', () => { describe('Query Type', () => {