Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gajus/slonik
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v34.2.2
Choose a base ref
...
head repository: gajus/slonik
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v34.3.0
Choose a head ref
  • 3 commits
  • 9 files changed
  • 1 contributor

Commits on Sep 26, 2023

  1. chore: add cspell

    gajus committed Sep 26, 2023
    Copy the full SHA
    f18b410 View commit details
  2. Copy the full SHA
    d8417c5 View commit details
  3. Copy the full SHA
    0fefebb View commit details
Showing with 1,014 additions and 24 deletions.
  1. +7 −0 .README/USAGE.md
  2. +7 −0 README.md
  3. +1 −1 benchmark/clients/postgres.js
  4. +17 −0 cspell.yml
  5. +955 −20 package-lock.json
  6. +3 −1 package.json
  7. +6 −0 src/utilities/parseDsn.ts
  8. +1 −0 test/helpers/createIntegrationTests.ts
  9. +17 −2 test/slonik/utilities/parseDsn.ts
7 changes: 7 additions & 0 deletions .README/USAGE.md
Original file line number Diff line number Diff line change
@@ -29,6 +29,13 @@ postgresql://foo:bar@localhost
postgresql://foo@localhost/bar?application_name=baz
```

Unix-domain socket connection is chosen if the host part is either empty or looks like an absolute path name.

```text
postgresql:///dbname?host=/var/lib/postgresql
postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
```

Other configurations are available through the [`clientConfiguration` parameter](https://github.com/gajus/slonik#api).

### Create connection
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -453,6 +453,13 @@ postgresql://foo:bar@localhost
postgresql://foo@localhost/bar?application_name=baz
```

Unix-domain socket connection is chosen if the host part is either empty or looks like an absolute path name.

```text
postgresql:///dbname?host=/var/lib/postgresql
postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
```

Other configurations are available through the [`clientConfiguration` parameter](https://github.com/gajus/slonik#api).

<a name="user-content-slonik-usage-create-connection"></a>
2 changes: 1 addition & 1 deletion benchmark/clients/postgres.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ const postgres = require('postgres');
const sql = postgres('postgres://postgres@127.0.0.1:5432', {
// Unlike "pg", "pg-promise" and "slonik", "postgres" does provide a method to explicitly create a connection.
// https://github.com/porsager/postgres/tree/v3.0.0#the-connection-pool
// `max: 1` mimics this behaviour as close as possible.
// `max: 1` mimics this behavior as close as possible.
max: 1,
});

17 changes: 17 additions & 0 deletions cspell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
allowCompoundWords: true
dictionaries:
- sql
- typescript
ignorePaths:
- node_modules
- dist
- README.md
language: en
minWordLength: 5
version: '0.2'
words:
- slonik
- gajus
- kuizinas
- roarr
- plpgsql
975 changes: 955 additions & 20 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
"@types/sinon": "^10.0.15",
"@types/through2": "^2.0.38",
"ava": "^5.3.0",
"cspell": "^7.3.6",
"delay": "^5.0.0",
"eslint": "^8.41.0",
"eslint-config-canonical": "^41.0.5",
@@ -89,10 +90,11 @@
"scripts": {
"build": "rm -fr ./dist && tsc --project ./tsconfig.build.json",
"create-readme": "gitdown ./.README/README.md --output-file ./README.md",
"lint:cspell": "cspell . --no-progress --gitignore",
"lint:eslint": "eslint --cache ./src ./test",
"lint:knip": "knip",
"lint:tsc": "tsc --noEmit",
"lint": "npm run lint:eslint && npm run lint:knip && npm run lint:tsc",
"lint": "npm run lint:cspell && npm run lint:eslint && npm run lint:knip && npm run lint:tsc",
"test": "nyc ava --verbose --serial"
},
"types": "./dist/index.d.ts",
6 changes: 6 additions & 0 deletions src/utilities/parseDsn.ts
Original file line number Diff line number Diff line change
@@ -17,6 +17,12 @@ export const parseDsn = (dsn: string): ConnectionOptions => {

if (url.host) {
connectionOptions.host = decodeURIComponent(url.hostname);
} else if (url.searchParams.has('host')) {
const host = url.searchParams.get('host');

if (typeof host === 'string' && host) {
connectionOptions.host = host;
}
}

if (url.port) {
1 change: 1 addition & 0 deletions test/helpers/createIntegrationTests.ts
Original file line number Diff line number Diff line change
@@ -660,6 +660,7 @@ export const createIntegrationTests = (
PgPool,
});

// cspell:disable-next-line
const payload = 'foobarbazqux';

await pool.query(sql.unsafe`
19 changes: 17 additions & 2 deletions test/slonik/utilities/parseDsn.ts
Original file line number Diff line number Diff line change
@@ -38,12 +38,27 @@ test('postgresql://fo%2Fo:b%2Far@localhost/ba%2Fz', testParse, {
username: 'fo/o',
});
test(
'postgresql://db_user:db_password@%2Fcloudsql%2Fproject-id%3Aregion-id1%3Acloudsqlinstance-name/dbname',
// cspell: disable-next-line
'postgresql://db_user:db_password@%2Fcloudsql%2Fproject-id%3Aregion-id1%3Acloudsqlinstance-name/database-name',
testParse,
{
databaseName: 'dbname',
databaseName: 'database-name',
host: '/cloudsql/project-id:region-id1:cloudsqlinstance-name',
password: 'db_password',
username: 'db_user',
},
);

// https://github.com/gajus/slonik/issues/468#issuecomment-1736020990
// cspell: disable-next-line
test('postgresql://%2Fvar%2Flib%2Fpostgresql/database-name', testParse, {
databaseName: 'database-name',
host: '/var/lib/postgresql',
});

// https://github.com/gajus/slonik/issues/468#issuecomment-1736020990
// cspell: disable-next-line
test('postgresql:///database-name?host=/var/lib/postgresql', testParse, {
databaseName: 'database-name',
host: '/var/lib/postgresql',
});