-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lars-Erik Roald
committed
Nov 21, 2024
1 parent
7b17403
commit 1479717
Showing
5 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function parseSearchPathParam(connectionString = '') { | ||
const [, queryString] = connectionString.split('?'); | ||
if (!queryString) | ||
return; | ||
const params = new URLSearchParams(queryString); | ||
const searchPath = params.get('search_path'); | ||
return searchPath; | ||
} | ||
|
||
module.exports = parseSearchPathParam; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { describe, test, beforeAll, expect } from 'vitest'; | ||
const map = require('./db'); | ||
|
||
const initPg = require('./initPg'); | ||
|
||
beforeAll(async () => { | ||
await insertData('pg'); | ||
|
||
async function insertData(dbName) { | ||
const { db, init } = getDb(dbName); | ||
await init(db); | ||
} | ||
}); | ||
|
||
describe('search path custom', () => { | ||
test('pgWithSchema', async () => await verify('pgWithSchema')); | ||
|
||
async function verify(dbName) { | ||
const { db } = getDb(dbName); | ||
|
||
const customer = await db.withSchema.insert({ | ||
name: 'Voldemort', | ||
}); | ||
|
||
const expected = { | ||
id: 1, | ||
name: 'Voldemort', | ||
}; | ||
|
||
expect(customer).toEqual(expected); | ||
} | ||
}); | ||
|
||
const connections = { | ||
pg: { | ||
db: map({ db: con => con.postgres('postgres://postgres:postgres@postgres/postgres', { size: 1 }) }), | ||
init: initPg | ||
}, | ||
pgWithSchema: { | ||
db: map({ db: con => con.postgres('postgres://postgres:postgres@postgres/postgres?search_path=custom', { size: 1 }) }), | ||
} | ||
}; | ||
|
||
function getDb(name) { | ||
if (name === 'pg') | ||
return connections.pg; | ||
if (name === 'pgWithSchema') | ||
return connections.pgWithSchema; | ||
else | ||
throw new Error('unknown'); | ||
} |