Skip to content
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
15 changes: 1 addition & 14 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ jobs:
- name: launchql/client
run: cd ./packages/client && yarn test
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_HOST: pg_db
POSTGRES_PORT: 5432
DATABASE_URL: postgres://postgres:password@pg_db:5432/postgres
TEST_DATABASE_URL: postgres://postgres:password@pg_db:5432/postgres

- name: launchql/orm
run: cd ./packages/orm && yarn test
Expand Down Expand Up @@ -84,15 +80,6 @@ jobs:
AWS_SECRET_KEY: minioadmin
AWS_REGION: us-east-1
BUCKET_NAME: test-bucket

- name: launchql/stream-to-s3
run: cd ./packages/stream-to-s3 && yarn test
env:
MINIO_ENDPOINT: http://minio_cdn:9000
AWS_ACCESS_KEY: minioadmin
AWS_SECRET_KEY: minioadmin
AWS_REGION: us-east-1
BUCKET_NAME: test-bucket

- name: launchql/upload-names
run: cd ./packages/upload-names && yarn test
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@launchql/migrate": "^2.0.0",
"@launchql/explorer": "^2.0.0",
"@launchql/server": "^2.0.0",
"@launchql/types": "^2.0.0",
"chalk": "^4.1.0",
"deepmerge": "^4.3.1",
"inquirerer": "^1.9.1",
Expand Down
24 changes: 15 additions & 9 deletions packages/cli/src/commands/explorer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LaunchQLExplorer as explorer, ExplorerOptions } from '@launchql/explorer';
import { LaunchQLExplorer as explorer } from '@launchql/explorer';
import { CLIOptions, Inquirerer, Question } from 'inquirerer';
import chalk from 'chalk';
import { getEnvOptions, LaunchQLOptions } from '@launchql/types';

const questions: Question[] = [
{
Expand Down Expand Up @@ -36,7 +37,8 @@ const questions: Question[] = [
type: 'number',
// alias: 'p',
required: false,
default: 5555
default: 5555,
useDefault: true
},
{
name: 'origin',
Expand Down Expand Up @@ -64,13 +66,17 @@ export default async (
simpleInflection
} = await prompter.prompt(argv, questions);

const options: ExplorerOptions = {
oppositeBaseNames,
origin,
port,
postgis,
simpleInflection
};
const options: LaunchQLOptions = getEnvOptions({
features: {
oppositeBaseNames,
simpleInflection,
postgis
},
server: {
origin,
port
}
});

console.log(chalk.green('\n✅ Selected Configuration:'));
for (const [key, value] of Object.entries(options)) {
Expand Down
22 changes: 14 additions & 8 deletions packages/cli/src/commands/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LaunchQLServer as server, ServerOptions } from '@launchql/server';
import { LaunchQLServer as server } from '@launchql/server';
import { CLIOptions, Inquirerer, Question } from 'inquirerer';
import chalk from 'chalk';
import { getEnvOptions, LaunchQLOptions } from '@launchql/types';

const questions: Question[] = [
{
Expand Down Expand Up @@ -36,7 +37,8 @@ const questions: Question[] = [
type: 'number',
// alias: 'p',
required: false,
default: 5555
default: 5555,
useDefault: true
},
// {
// name: 'origin',
Expand All @@ -63,12 +65,16 @@ export default async (
simpleInflection
} = await prompter.prompt(argv, questions);

const options: ServerOptions = {
oppositeBaseNames,
port,
postgis,
simpleInflection
};
const options: LaunchQLOptions = getEnvOptions({
features: {
oppositeBaseNames,
simpleInflection,
postgis
},
server: {
port
}
});

console.log(chalk.green('\n✅ Selected Configuration:'));
for (const [key, value] of Object.entries(options)) {
Expand Down
5 changes: 3 additions & 2 deletions packages/client/__tests__/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
process.env.DATABASE_URL = process.env.DATABASE_URL ?? 'postgres://postgres:password@localhost:5432/postgres';
import { PoolClient } from 'pg';
import { Database } from '../src';

let client: Database;

const databaseUrl = process.env.TEST_DATABASE_URL || 'postgres://postgres:password@localhost:5432/postgres';

beforeAll(() => {
client = new Database();
client = new Database(databaseUrl);
});

afterAll(async () => {
Expand Down
1 change: 0 additions & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"keywords": [],
"dependencies": {
"@types/pg": "^8.11.10",
"envalid": "^8.0.0",
"pg": "^8.13.1"
}
}
10 changes: 0 additions & 10 deletions packages/client/src/env.ts

This file was deleted.

23 changes: 4 additions & 19 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
import { Pool, PoolClient } from 'pg';

import env from './env';

export class Database {
private static instance: Database;
private pool: Pool;

constructor() {
if (Database.instance) {
return Database.instance;
}

const pgPoolConfig = {
connectionString: env.DATABASE_URL,
};
this.pool = new Pool(pgPoolConfig);
constructor(databaseUrl: string) {
this.pool = new Pool({ connectionString: databaseUrl });

// Ensure the pool is closed on process termination
process.on('SIGTERM', async () => {
await this.shutdown();
});

Database.instance = this;
return this;
}

/**
* Executes a callback function within a database transaction.
* @param fn - A callback function that receives a PoolClient to perform database operations.
*/
async withTransaction(fn: (client: PoolClient) => Promise<void>): Promise<void> {
const client = await this.pool.connect();
Expand All @@ -39,7 +24,7 @@ export class Database {
} catch (e) {
console.error('Error during transaction:', e);
await client.query('ROLLBACK');
throw e; // Re-throw the error to propagate it
throw e;
}
} finally {
client.release();
Expand All @@ -52,4 +37,4 @@ export class Database {
async shutdown(): Promise<void> {
await this.pool.end();
}
}
}
2 changes: 1 addition & 1 deletion packages/explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@launchql/server-utils": "^0.4.0",
"@launchql/url-domains": "^0.1.0",
"@launchql/upload-names": "^0.1.0",
"envalid": "^8.0.0",
"@launchql/types": "^2.0.0",
"express": "^5.1.0",
"graphile-build": "^4.14.1",
"graphql-upload": "^17.0.0",
Expand Down
21 changes: 0 additions & 21 deletions packages/explorer/src/env.ts

This file was deleted.

Loading