Initial commit
commit
67e28e9071
@ -0,0 +1 @@
|
||||
node_modules
|
@ -0,0 +1,34 @@
|
||||
# postgresql-socket-url
|
||||
|
||||
Generates a well-formed URL for a given PostgreSQL domain socket path and database name. Useful when you want to use a database driver (like `pg`) to connect to PostgreSQL through a Unix domain socket.
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
"use strict";
|
||||
|
||||
const postgresqlSocketUrl = require("postgresql-socket-url");
|
||||
|
||||
let url = postgresqlSocketUrl({
|
||||
socketPath: "/tmp",
|
||||
database: "myproject"
|
||||
});
|
||||
|
||||
console.log(url); // socket:/tmp?db=myproject
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### postgresqlSocketUrl(options)
|
||||
|
||||
Generates the URL to connect to.
|
||||
|
||||
- __options:__
|
||||
- __socketPath:__ The path of the folder that __contains__ the PostgreSQL socket. *Not* the path of the socket itself.
|
||||
- __database:__ The name of the database to connect to.
|
||||
|
||||
## Changelog
|
||||
|
||||
### 1.0.0 (September 14, 2019)
|
||||
|
||||
Initial release.
|
@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
const postgresqlSocketUrl = require(".");
|
||||
|
||||
let url = postgresqlSocketUrl({
|
||||
socketPath: "/tmp",
|
||||
database: "myproject"
|
||||
});
|
||||
|
||||
console.log(url); // socket:/tmp?db=myproject
|
@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
|
||||
const url = require("url");
|
||||
const { validateOptions, required, isString } = require("validatem");
|
||||
|
||||
module.exports = function postgresqlSocketUrl({ socketPath, database } = {}) {
|
||||
validateOptions(arguments, {
|
||||
socketPath: [ required, isString ],
|
||||
database: [ required, isString ]
|
||||
});
|
||||
|
||||
return url.format({
|
||||
protocol: "socket",
|
||||
slashes: false,
|
||||
pathname: socketPath,
|
||||
query: {
|
||||
db: database
|
||||
}
|
||||
});
|
||||
};
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "postgresql-socket-url",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"repository": "http://git.cryto.net/joepie91/postgresql-socket-url.git",
|
||||
"author": "Sven Slootweg <admin@cryto.net>",
|
||||
"license": "WTFPL OR CC0-1.0",
|
||||
"dependencies": {
|
||||
"validatem": "^0.2.0"
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
assure-array@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/assure-array/-/assure-array-1.0.0.tgz#4f4ad16a87659d6200a4fb7103462033d216ec1f"
|
||||
integrity sha1-T0rRaodlnWIApPtxA0YgM9IW7B8=
|
||||
|
||||
create-error@^0.3.1:
|
||||
version "0.3.1"
|
||||
resolved "https://registry.yarnpkg.com/create-error/-/create-error-0.3.1.tgz#69810245a629e654432bf04377360003a5351a23"
|
||||
integrity sha1-aYECRaYp5lRDK/BDdzYAA6U1GiM=
|
||||
|
||||
default-value@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/default-value/-/default-value-1.0.0.tgz#8c6f52a5a1193fe78fdc9f86eb71d16c9757c83a"
|
||||
integrity sha1-jG9SpaEZP+eP3J+G63HRbJdXyDo=
|
||||
dependencies:
|
||||
es6-promise-try "0.0.1"
|
||||
|
||||
es6-promise-try@0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/es6-promise-try/-/es6-promise-try-0.0.1.tgz#10f140dad27459cef949973e5d21a087f7274b20"
|
||||
integrity sha1-EPFA2tJ0Wc75SZc+XSGgh/cnSyA=
|
||||
|
||||
validatem@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/validatem/-/validatem-0.2.0.tgz#0cde815813f3c8a33615bf09370e88d511a65658"
|
||||
integrity sha512-fSW8L19US3smdm/E5tw7zTR3WgC+yGiBf67zhxCgVJExujZui2t8gwVyX05u9tcIBu/90tzqsD9hfMR0VAGKUA==
|
||||
dependencies:
|
||||
assure-array "^1.0.0"
|
||||
create-error "^0.3.1"
|
||||
default-value "^1.0.0"
|
Loading…
Reference in New Issue