Skip to content

Connection constructor named object #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/connections/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { QueryType } from '../query-params'
import { Query, constructRawQuery } from '../query'
import { Connection } from './index'

export type CloudflareD1ConnectionDetails = {
apiKey: string,
accountId: string,
databaseId: string
};

export class CloudflareD1Connection implements Connection {
// The Cloudflare API key with D1 access
apiKey: string | undefined
Expand All @@ -16,11 +22,13 @@ export class CloudflareD1Connection implements Connection {
* account ID, and database ID.
*
* @param apiKey - The API key to be used for authentication.
* @param accountId - The account ID to be used for authentication.
* @param databaseId - The database ID to be used for querying.
*/
constructor(apiKey: string, accountId: string, databaseId: string) {
this.apiKey = apiKey
this.accountId = accountId
this.databaseId = databaseId
constructor(private _: CloudflareD1ConnectionDetails) {
this.apiKey = _.apiKey;
this.accountId = _.accountId;
this.databaseId = _.databaseId;
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/connections/outerbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { Query, constructRawQuery } from '../query'
import { Connection } from './index'
export const API_URL = 'https://app.outerbase.com'

export type OuterbaseConnectionDetails = {
apiKey: string
};

export class OuterbaseConnection implements Connection {
// The API key used for Outerbase authentication
api_key: string | undefined
Expand All @@ -15,8 +19,10 @@ export class OuterbaseConnection implements Connection {
*
* @param apiKey - The API key to be used for authentication.
*/
constructor(private apiKey: string) {
this.api_key = apiKey
constructor(private _: {
apiKey: string
}) {
this.api_key = _.apiKey;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/connections/cloudflare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { QueryType } from 'src/query-params'

describe('CloudflareD1Connection', () => {
describe('Query Type', () => {
const connection = new CloudflareD1Connection(
'API_KEY',
'ACCOUNT_ID',
'DATABASE_ID'
)
const connection = new CloudflareD1Connection({
apiKey: 'API_KEY',
accountId: 'ACCOUNT_ID',
databaseId: 'DATABASE_ID'
})

test('Query type is set to positional', () => {
expect(connection.queryType).toBe(QueryType.positional)
Expand Down
4 changes: 3 additions & 1 deletion tests/connections/outerbase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { QueryType } from 'src/query-params'

describe('OuterbaseConnection', () => {
describe('Query Type', () => {
const connection = new OuterbaseConnection('FAKE_API_KEY')
const connection = new OuterbaseConnection({
apiKey: 'FAKE_API_KEY'
})

test('Query type is set to named', () => {
expect(connection.queryType).toBe(QueryType.named)
Expand Down
8 changes: 6 additions & 2 deletions tests/to-string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { Outerbase, equals, equalsNumber } from 'src/index'

describe('toString', () => {
describe('SELECT statements', () => {
const connection = new OuterbaseConnection('FAKE_API_KEY')
const connection = new OuterbaseConnection({
apiKey: 'FAKE_API_KEY'
})
const db = Outerbase(connection)

test('Select from one table, one column', () => {
Expand Down Expand Up @@ -62,7 +64,9 @@ describe('toString', () => {
})

describe('queryBuilder - Reserved keywords get quotes', () => {
const connection = new OuterbaseConnection('FAKE_API_KEY')
const connection = new OuterbaseConnection({
apiKey: 'FAKE_API_KEY'
})
const db = Outerbase(connection)

test('toString – Not reserved keyword "users" is not wrapped in quotes', () => {
Expand Down
Loading