Skip to content
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

Add postgres adapter #96

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"test": "./tests/test.sh --coverage",
"test:ignoreTodo": "pnpm test:surrealdb-ignoreTodo && pnpm test:typedb-ignoreTodo && pnpm test:multidb",
"test:multidb": "./tests/test.sh multidb",
"test:query": "./tests/test.sh query.test.ts",
"test:surrealdb-ignoreTodo": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=refs ./tests/test.sh tests/unit/allTests.test.ts -t \"^(?!.*TODO{.*[S].*}:).*\"",
"test:surrealdb-ignoreTodo:edges": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=edges ./tests/test.sh tests/unit -t \"^(?!.*TODO{.*[S].*}:).*\"",
"test:surrealdb-query:edges": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=edges ./tests/test.sh tests/unit/queries/query.test.ts",
"test:surrealdb-query:refs": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=refs ./tests/test.sh tests/unit/queries/query.test.ts",
"test:surrealdb-mutation:edges": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=edges ./tests/test.sh tests/unit/mutations",
"test:surrealdb-mutation:refs": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=refs ./tests/test.sh tests/unit/mutations",
"test:surrealdb-schema": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=refs ./tests/test.sh tests/unit/schema",
"test:postgres-query": "cross-env BORM_TEST_ADAPTER=postgresDB ./tests/postgres.sh tests/unit/queries/query.test.ts -t \"^(?!.*TODO{.*[P].*}:).*\"",
"test:surrealdb-ignoreTodo": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=refs ./tests/surreal.sh tests/unit/allTests.test.ts -t \"^(?!.*TODO{.*[S].*}:).*\"",
"test:surrealdb-ignoreTodo:edges": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=edges ./tests/surreal.sh tests/unit -t \"^(?!.*TODO{.*[S].*}:).*\"",
"test:surrealdb-query:edges": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=edges ./tests/surreal.sh tests/unit/queries/query.test.ts",
"test:surrealdb-query:refs": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=refs ./tests/surreal.sh tests/unit/queries/query.test.ts",
"test:surrealdb-mutation:edges": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=edges ./tests/surreal.sh tests/unit/mutations",
"test:surrealdb-mutation:refs": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=refs ./tests/surreal.sh tests/unit/mutations",
"test:surrealdb-schema": "cross-env BORM_TEST_ADAPTER=surrealDB BORM_TEST_SURREALDB_LINK_MODE=refs ./tests/surreal.sh tests/unit/schema",
"test:typedb-ignoreTodo": "cross-env BORM_TEST_ADAPTER=typeDB vitest run tests/unit/allTests.test.ts -t \"^(?!.*TODO{.*[T].*}:).*\" ",
"test:typedb-mutation": "cross-env BORM_TEST_ADAPTER=typeDB vitest run unit/mutations",
"test:typedb-query": "cross-env BORM_TEST_ADAPTER=typeDB vitest run tests/unit/queries --watch",
Expand Down Expand Up @@ -67,6 +67,7 @@
"immer": "10.1.1",
"nanoid": "^5.0.7",
"object-traversal": "^1.0.1",
"pg": "^8.13.1",
"radash": "^12.1.0",
"robot3": "^0.4.1",
"surrealdb": "^1.0.6",
Expand All @@ -76,6 +77,7 @@
"devDependencies": {
"@blitznocode/eslint-config": "^1.1.0",
"@types/node": "^22.5.5",
"@types/pg": "^8.11.10",
"@types/uuid": "^10.0.0",
"@vitest/coverage-v8": "^2.1.1",
"cross-env": "^7.0.3",
Expand All @@ -101,5 +103,6 @@
"homepage": "https://github.com/Blitzapps/blitz-orm#readme",
"directories": {
"test": "tests"
}
},
"packageManager": "pnpm@8.10.2+sha512.0782093d5ba6c7ad9462081bc1ef0775016a4b4109eca1e1fedcea6f110143af5f50993db36c427d4fa8c62be3920a3224db12da719d246ca19dd9f18048c33c"
}
21 changes: 15 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { enableMapSet } from 'immer';
import { runMutationMachine } from './stateMachine/mutation/mutationMachine';
import { runQueryMachine } from './stateMachine/query/queryMachine';
import { SimpleSurrealClient } from './adapters/surrealDB/client';
import { Client } from 'pg';

export * from './types';

Expand All @@ -47,10 +48,20 @@ class BormClient {
getDbHandles = () => this.dbHandles;

init = async () => {
const dbHandles: AllDbHandles = { typeDB: new Map(), surrealDB: new Map() };
const dbHandles: AllDbHandles = { typeDB: new Map(), surrealDB: new Map(), postgresDB: new Map() };
await Promise.all(
this.config.dbConnectors.map(async (dbc) => {
if (dbc.provider === 'surrealDB') {
if (dbc.provider === 'postgresDB') {
const client = new Client({
host: dbc.host,
port: dbc.port,
user: dbc.user,
password: dbc.password,
database: dbc.dbName,
});
await client.connect();
dbHandles.postgresDB.set(dbc.id, { client });
} else if (dbc.provider === 'surrealDB') {
const client = new SimpleSurrealClient({
url: dbc.url,
username: dbc.username,
Expand All @@ -67,8 +78,7 @@ class BormClient {
// totalConnections: 8,
// });
dbHandles.surrealDB.set(dbc.id, { client, providerConfig: dbc.providerConfig });
}
if (dbc.provider === 'typeDB' && dbc.dbName) {
} else if (dbc.provider === 'typeDB' && dbc.dbName) {
// const client = await TypeDB.coreClient(dbc.url);
// const clientErr = undefined;
const [clientErr, client] = await tryit(TypeDB.coreDriver)(dbc.url);
Expand All @@ -89,8 +99,7 @@ class BormClient {
}`;
throw new Error(message);
}
}
if (dbc.provider === 'typeDBCluster' && dbc.dbName) {
} else if (dbc.provider === 'typeDBCluster' && dbc.dbName) {
const credential = new TypeDBCredential(dbc.username, dbc.password, dbc.tlsRootCAPath);
const [clientErr, client] = await tryit(TypeDB.cloudDriver)(dbc.addresses, credential);

Expand Down
Loading