embedded-postgres
Advanced tools
Comparing version 12.22.0-beta.14 to 12.22.0-beta.15
@@ -20,2 +20,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const { Client } = pg; | ||
/** | ||
* We have to specify the LC_MESSAGES locale because we rely on inspecting the | ||
* output of the `initdb` command to see if Postgres is ready. As we're looking | ||
* for a particular string, we need to force that string into the right locale. | ||
* @see https://github.com/leinelissen/embedded-postgres/issues/15 | ||
*/ | ||
const LC_MESSAGES_LOCALE = 'en_US.UTF-8'; | ||
// The default configuration options for the class | ||
@@ -110,2 +117,3 @@ const defaults = { | ||
yield new Promise((resolve, reject) => { | ||
var _a; | ||
const process = spawn(initdb, [ | ||
@@ -116,4 +124,11 @@ `--pgdata=${this.options.databaseDir}`, | ||
`--pwfile=${passwordFile}`, | ||
`--lc-messages=${LC_MESSAGES_LOCALE}`, | ||
...this.options.initdbFlags, | ||
], Object.assign({ stdio: 'inherit' }, permissionIds)); | ||
], Object.assign(Object.assign({}, permissionIds), { env: { LC_MESSAGES: LC_MESSAGES_LOCALE } })); | ||
// Connect to stderr, as that is where the messages get sent | ||
(_a = process.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (chunk) => { | ||
// Parse the data as a string and log it | ||
const message = chunk.toString('utf-8'); | ||
this.options.onLog(message); | ||
}); | ||
process.on('exit', (code) => { | ||
@@ -156,3 +171,3 @@ if (code === 0) { | ||
...this.options.postgresFlags, | ||
], Object.assign({}, permissionIds)); | ||
], Object.assign(Object.assign({}, permissionIds), { env: { LC_MESSAGES: LC_MESSAGES_LOCALE } })); | ||
// Connect to stderr, as that is where the messages get sent | ||
@@ -159,0 +174,0 @@ (_a = this.process.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (chunk) => { |
{ | ||
"name": "embedded-postgres", | ||
"version": "12.22.0-beta.14", | ||
"version": "12.22.0-beta.15", | ||
"description": "A package to run an embedded Postgresql database right from NodeJS", | ||
@@ -27,3 +27,3 @@ "exports": "./dist/index.js", | ||
"devDependencies": { | ||
"@embedded-postgres/symlink-reader": "^12.22.0-beta.14", | ||
"@embedded-postgres/symlink-reader": "^12.22.0-beta.15", | ||
"@types/async-exit-hook": "^2.0.0", | ||
@@ -36,10 +36,10 @@ "@types/pg": "^8.6.5", | ||
"optionalDependencies": { | ||
"@embedded-postgres/darwin-arm64": "^12.22.0-beta.14", | ||
"@embedded-postgres/darwin-x64": "^12.22.0-beta.14", | ||
"@embedded-postgres/linux-arm": "^12.22.0-beta.14", | ||
"@embedded-postgres/linux-arm64": "^12.22.0-beta.14", | ||
"@embedded-postgres/linux-ia32": "^12.22.0-beta.14", | ||
"@embedded-postgres/linux-ppc64": "^12.22.0-beta.14", | ||
"@embedded-postgres/linux-x64": "^12.22.0-beta.14", | ||
"@embedded-postgres/windows-x64": "^12.22.0-beta.14" | ||
"@embedded-postgres/darwin-arm64": "^12.22.0-beta.15", | ||
"@embedded-postgres/darwin-x64": "^12.22.0-beta.15", | ||
"@embedded-postgres/linux-arm": "^12.22.0-beta.15", | ||
"@embedded-postgres/linux-arm64": "^12.22.0-beta.15", | ||
"@embedded-postgres/linux-ia32": "^12.22.0-beta.15", | ||
"@embedded-postgres/linux-ppc64": "^12.22.0-beta.15", | ||
"@embedded-postgres/linux-x64": "^12.22.0-beta.15", | ||
"@embedded-postgres/windows-x64": "^12.22.0-beta.15" | ||
}, | ||
@@ -60,3 +60,3 @@ "dependencies": { | ||
}, | ||
"gitHead": "474ea62bcc94fa85d5f8835b32da12ce385f3437" | ||
"gitHead": "acea2eb6a39b95c7af2c3099af905c44ee48fc78" | ||
} |
158
README.md
@@ -1,9 +0,32 @@ | ||
# embedded-postgres | ||
A Node package that allows you to spawn a Postgresql cluster programatically. | ||
![Embedded | ||
Postgres](https://github.com/leinelissen/embedded-postgres/raw/master/docs/images/embedded-postgres-header.svg) | ||
## Usage | ||
``` | ||
<div align="center"> | ||
![npm](https://img.shields.io/npm/v/embedded-postgres) | ||
![npm type definitions](https://img.shields.io/npm/types/embedded-postgres) | ||
![npm](https://img.shields.io/npm/dy/embedded-postgres) | ||
![NPM](https://img.shields.io/npm/l/embedded-postgres) | ||
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/leinelissen/embedded-postgres/test.yml) | ||
</div> | ||
<h3 align="center"> | ||
🐘 A Node package that spawns PostgresQL clusters programatically. | ||
</h3> | ||
## Installation | ||
`embedded-postgres` is available from NPM: | ||
```sh | ||
npm i embedded-postgres | ||
``` | ||
<br /> | ||
## Usage | ||
This package contains a simple API that allows you to create clusters, start | ||
them, create / delete database and stop any existing processes. | ||
```ts | ||
@@ -23,3 +46,3 @@ import EmbeddedPostgres from 'embedded-postgres'; | ||
// Create the cluster config files | ||
await pg.inititialize(); | ||
await pg.initialise(); | ||
@@ -45,5 +68,126 @@ // Start the server | ||
<br /> | ||
## Credits | ||
## PostgresQL Versions | ||
This package aims to track the [PostgresQL support | ||
policy](https://www.postgresql.org/support/versioning/) for supported versions. | ||
Additionally, we track the binaries that are created upstream in [zonky's | ||
embedded-postgres-binaries](https://github.com/zonkyio/embedded-postgres). This | ||
leads to the following current support matrix: | ||
| Platform / Architecture | 12.20.0 | 13.16.0 | 14.13.0 | 15.8.0 | 16.4.0 | 17.0.0 | | ||
|---------------------------|---------|---------|---------|--------|--------|--------| | ||
| 🍎 Darwin / x64 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | ||
| 🍎 Darwin / arm64[[1]](https://github.com/zonkyio/embedded-postgres/issues/86#issuecomment-1120425822) | 🚫 | 🚫 | 🚫 | ✅ | ✅ | ✅ | | ||
| 🪟 Windows / x64 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | ||
| 🐧 Linux / x64 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | ||
| 🐧 Linux / arm | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | ||
| 🐧 Linux / arm64 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | ||
| 🐧 Linux / ia32 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | ||
| 🐧 Linux / ppc64 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | ||
In order to install a particular version, look for the latest tag in | ||
[NPM](https://www.npmjs.com/package/embedded-postgres). For example, if you | ||
would like to install `v10.20.0`, you can currently use the following tag: | ||
```sh | ||
npm i embedded-postgres@10.20.0-beta.6 | ||
``` | ||
Installing particular versions of PostgresQL (i.e. versions not released on NPM) | ||
is currently not possible. If you would have a need for doing so, please create | ||
an issue. | ||
<br /> | ||
## API | ||
Options in the constructor can be used to modify the behaviour of the | ||
application. The parameters that are available as part of the options can be | ||
seen here: | ||
| Property | Type | Description | | ||
|---|---|---| | ||
| databaseDir | string | The location where the data should be persisted to. Defaults to `./data/db` | | ||
| port | number | The port where the Postgres database should be listening. Defaults to: `5432` | | ||
| user | string | The username for logging into the Postgres database. Defaults to `postgres` | | ||
| password | string | The password for logging into the Postgres database. Defaults to `password` | | ||
| authMethod | 'scram-sha-256' \| 'password' \| 'md5' | The authentication method to use when authenticating against Postgres. Defaults to `password` | | ||
| persistent | boolean | Whether all data should be left in place when the database is shut down. Defaults to `true`. | | ||
| initdbFlags | string[] | Pass any additional flags to the initdb process. You can find all available flags here: https://www.postgresql.org/docs/current/app-initdb.html. Flags should be passed as a string array, e.g. `["--debug"]` or `["--locale=en-GB"]` Defaults to `[]` | ||
| postgresFlags | string[] | Pass any additional flags to the postgres process. You can find all available flags here: https://www.postgresql.org/docs/current/app-postgres.html. Flags should be passed as a string array, e.g. `["--debug"]` or `["--locale=en-GB"]`. Defaults to `[]`. | | ||
| createPostgresUser | boolean | Postgres does not allow binaries to be run by root. In case you're running in root-only enviroments, such as Docker containers, you may need to create an extra user on your system in order to be able to call the binaries. <br />NOTE: This WILL irreversibly modify your host system. The effects are somewhat minor, but it's still recommend to only use this in Docker containers. Defaults to `false`. | | ||
| onLog | (message \| string) => void | Pass in a custom logging handler. This will relay and console messages that are generated by the postgres and initdb processes. Defaults to `console.log` | | ||
| onError | (messageOrError \| string \| Error \| unknown) => void | Pass in a custom error logging handler. This will catch and stderr results coming in from the postgres and initdb processes. Defaults to `console.error` | | ||
<br /> | ||
## Contributing | ||
This package is open to issues, feedback, ideas and pull requests. Create an | ||
issue on this repository to get started! In order to get started with | ||
development, you might need some extra pointers | ||
### Development | ||
In order to get yourself situated for development, you will need to the | ||
reopistory up and running. In order to make this work, start with a relatively | ||
recent install of NodeJS (at least v18, v20+ recommended). You can then run this | ||
command to install all packages: | ||
``` | ||
npm install --force | ||
``` | ||
> [!NOTE] | ||
> You must include `--force` or else NPM will refuse to install the | ||
> dependencies for all packages, including those not for the current architecture. | ||
Then, you must pre-compile all Typescript using the following command: | ||
``` | ||
npm run build | ||
``` | ||
As soon as that is complete, we'll download the requisite PostgresQL binaries | ||
for your particular architecture using: | ||
``` | ||
npm run download | ||
``` | ||
Lastly, you can hop over to `packages/embedded-postgres` and do some development | ||
there: | ||
``` | ||
cd packages/embedded-postgres | ||
``` | ||
You can force automatic recompliation of the Typescript files by running: | ||
``` | ||
npm start | ||
``` | ||
Don't forget to add and run tests when you are developing new functionality. Add | ||
them to `tests/index.test.ts`, and run the tests by running: | ||
``` | ||
npm test | ||
``` | ||
<br /> | ||
## Troubleshotting | ||
### Running in Docker containers | ||
Running in Docker containers might fail, because many are setup to run with the | ||
root user as default. Either you resolve to setting up a container with a | ||
specific user yourself, or you set the `createPostgresUser` option to true, | ||
after which embedded-postgres will automatically set up a postgres user on the | ||
system for usage by your script. | ||
<br /> | ||
## Credits and Licensing | ||
Embedded Postgres was created by Lei Nelissen for [BMD | ||
Studio](https://bmd.studio). It is based on [zonky's embedded-postgres-binaries](https://github.com/zonkyio/embedded-postgres). | ||
Studio](https://bmd.studio). It is based on [zonky's | ||
embedded-postgres-binaries](https://github.com/zonkyio/embedded-postgres). The | ||
binaries are made available under the Apache License 2.0, whereas the specific | ||
code in this package is made available under the MIT license. | ||
<a href="https://bmd.studio"> | ||
<img src="https://github.com/leinelissen/embedded-postgres/raw/master/docs/images/logo-bmd.svg" alt="BMD Studio" width="150" height="150" /> | ||
</a> | ||
<br /> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32665
515
192