Skip to content

Commit

Permalink
Move QueryType to query-params
Browse files Browse the repository at this point in the history
  • Loading branch information
Brayden committed May 25, 2024
1 parent d508fc9 commit 50a8d98
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 24 deletions.
4 changes: 0 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ const { pathsToModuleNameMapper } = require('ts-jest')
const { compilerOptions } = require('./tsconfig')

pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>' })
const moduleNameMapper = pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/',
})
console.log(moduleNameMapper)

module.exports = {
preset: 'ts-jest',
Expand Down
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
3 changes: 2 additions & 1 deletion src/connections/cloudflare.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 2 additions & 13 deletions src/connections/index.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>) => Promise<any>
disconnect: () => Promise<any>
Expand Down
5 changes: 3 additions & 2 deletions src/connections/outerbase.ts
Original file line number Diff line number Diff line change
@@ -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

/**
Expand Down
12 changes: 12 additions & 0 deletions src/query-params.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>
export type QueryParamsPositional = any[]
export type QueryParams = QueryParamsNamed | QueryParamsPositional
Expand Down
2 changes: 1 addition & 1 deletion tests/connections/cloudflare.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/connections/outerbase.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down

0 comments on commit 50a8d98

Please sign in to comment.