Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
57 changes: 11 additions & 46 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,20 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: build

on:
push:
branches: [ master ]
branches: [main]
pull_request:
branches: [ master ]
branches: [main]

jobs:
build:
timeout-minutes: 4

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
node-version: [12.x]

runs-on: ${{ matrix.os }}

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: senecatest_ci_07y71809h1
POSTGRES_DB: senecatest_ci_629vv14
POSTGRES_USER: senecatest
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Connect to PostgreSQL
run: PGPASSWORD="${POSTGRES_PASSWORD}" psql -h localhost -U "${POSTGRES_USER}" -d "${POSTGRES_DB}" -f "./test/support/docker/dbschema.sql"
env:
POSTGRES_USER: "senecatest"
POSTGRES_PASSWORD: senecatest_ci_07y71809h1
POSTGRES_DB: "senecatest_ci_629vv14"

- name: Install dependencies
run: npm install

- name: Run the tests
run: npm test

- uses: actions/checkout@v4
- name: Use Node.js 24
uses: actions/setup-node@v4
with:
node-version: '24'
- run: npm install
- run: npm run build --if-present
- run: npm test
51 changes: 51 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes
* Focusing on what is best not just for us as individuals, but for the community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information without their explicit permission
* Other conduct which could reasonably be considered inappropriate professionally

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards
and will take appropriate and fair corrective action in response to any
behavior that they deem inappropriate, threatening, offensive, or harmful.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement.
All complaints will be reviewed and investigated promptly and fairly.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.

[homepage]: https://www.contributor-covenant.org
165 changes: 30 additions & 135 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,139 +1,45 @@
![Seneca](http://senecajs.org/files/assets/seneca-logo.png)
> A [Seneca.js](http://senecajs.org) data storage plugin

# seneca-postgres-store
# @seneca/postgres-store

[![npm version][npm-badge]][npm-url]
[![Build Status][travis-badge]][travis-url]
[![Dependency Status][david-badge]][david-url]
[![Coveralls][BadgeCoveralls]][Coveralls]
[![Gitter][gitter-badge]][gitter-url]

| ![Voxgig](https://www.voxgig.com/res/img/vgt01r.png) | This open source module is sponsored and supported by [Voxgig](https://www.voxgig.com). |
|---|---|

## Description

seneca-postgres-store is a [PostgreSQL][postgresqlorg] database plugin for the [Seneca][seneca] MVP toolkit. The plugin is using the [node-postgres][nodepg] driver.
For query generation it uses internally the [seneca-standard-query][standard-query] plugin and the standard functionality can be extended by using the [seneca-store-query][store-query] plugin.

Usage:

var Seneca = require('seneca');
var store = require('seneca-postgres-store');
## Install

var DBConfig = {
name: 'senecatest',
host: 'localhost',
username: 'senecatest',
password: 'senecatest',
port: 5432
}
...

var si = Seneca(DBConfig)
si.use(require('seneca-postgres-store'), DBConfig)
si.ready(function() {
var product = si.make('product')
...
})
...

### Seneca compatibility
Supports Seneca versions **1.x** - **3.x**

### Supported functionality
All Seneca data store supported functionality is implemented in [seneca-store-test](https://github.com/senecajs/seneca-store-test) as a test suite. The tests represent the store functionality specifications.

## Usage
You don't use this module directly. It provides an underlying data storage engine for the Seneca entity API:

```js
var entity = seneca.make$('typename')
entity.someproperty = "something"
entity.anotherproperty = 100

entity.save$(function (err, entity) { ... })
entity.load$({id: ...}, function (err, entity) { ... })
entity.list$({property: ...}, function (err, entity) { ... })
entity.remove$({id: ...}, function (err, entity) { ... })
```sh
npm install seneca
npm install @seneca/postgres-store
```

### Query Support

The standard Seneca query format is supported. See the [seneca-standard-query][standard-query] plugin for more details.

## Extended Query Support

By using the [seneca-store-query][store-query] plugin its query capabilities can be extended. See the plugin page for more details.

## Column name transformation, backward compatibility

In seneca-postgres-store 2.0 the internal CamelCase to snake_case column names conversion was removed.

To update from seneca-postgres-store 1.x to 2.x on systems built with seneca-postgres-store 1.x you must provide to the plugin through its options the functions that do the CamelCase to snake_case conversion and back. Any other name transformations to and from database column name can be also made with these. Example:
## Quick Example

```js
var DefaultConfig = {
...
fromColumnName: function (attr) {
// apply some conversion on column names
return attr.toUpperCase()
},
toColumnName: function (attr) {
// convert back column names
return attr.toLowerCase()
}
}
seneca.use(require('seneca-postgres-store'), DefaultConfig)
const Seneca = require('seneca')
var seneca = Seneca().use('postgres-store', { ... })
```

For a fully functional CamelCase to snake_case implementation sample please look in the postgres.test.js at the 'Column Names conversions' test code.

## Limits

By default queries are limited to 20 values. This can be bypassed by passing the `nolimit` option, which if set to true will not limit any queries.

## Fields

To filter the fields returned from the `list` operation, pass a `fields$` array of column names to return. If no `fields$` are passed, all fields are returned (i.e. `select *` is used). e.g.

query.fields$ = ['id', 'name']
## More Examples

See [test/](test/) for usage examples.

Note: The implicit id that is generated on save$ has uuid value. To override this you must provide entity.id$ with a desired value.
## Motivation

### Custom ID generator
A Postgres data store plugin for the Seneca framework.

To generate custom IDs it is exposed a seneca action pattern hook that can be overwritten:
## Support

If you are having difficulty, open an issue on the GitHub repo.

```js
seneca.add({role: 'sql', hook: 'generate_id', target: <store name>}, function (args, done) {
return done(null, {id: idPrefix + Uuid()})
})

```
## API

### Native Driver
As with all seneca stores, you can access the native driver, in this case, the `pg`
`connection` object using `entity.native$(function (err, connectionPool, release) {...})`.
Please make sure that you release the connection after using it.

```
entity.native$( function (err, client, releaseConnection){
// ... you can use client
// ... then release connection
releaseConnection()
} )
```
See [README](README.md) and Seneca docs for message patterns.

## Contributing
The [Senecajs org][] encourages open participation. If you feel you
can help in any way, be it with documentation, examples, extra
testing, or new features please get in touch.

## To run tests with Docker
### Running tests with Docker

Build the PostgreSQL Docker image:

```sh
Expand All @@ -160,27 +66,16 @@ npm run test
Before the tests can be run you must run `docker-machine env default` and copy the docker host address (example: '192.168.99.100').
This address must be inserted into the test/default_config.json file as the value for the host variable. The tests can now be run.

## Background

This plugin uses the [pg](https://node-postgres.com/) driver.


## License
Copyright (c) 2012 - 2016, Marian Radulescu and other contributors.
Licensed under [MIT][].

[MIT]: ./LICENSE
[npm-badge]: https://img.shields.io/npm/v/seneca-postgres-store.svg
[npm-url]: https://npmjs.com/package/seneca-postgres-store
[travis-badge]: https://api.travis-ci.org/senecajs/seneca-postgres-store.svg
[travis-url]: https://travis-ci.org/senecajs/seneca-postgres-store
[david-badge]: https://david-dm.org/senecajs/seneca-postgres-store.svg
[david-url]: https://david-dm.org/senecajs/seneca-postgres-store
[codeclimate-badge]: https://codeclimate.com/github/senecajs/seneca-postgres-store/badges/gpa.svg
[codeclimate-url]: https://codeclimate.com/github/senecajs/seneca-postgres-store
[gitter-badge]: https://badges.gitter.im/Join%20Chat.svg
[gitter-url]: https://gitter.im/senecajs/seneca
[standard-query]: https://github.com/senecajs/seneca-standard-query
[store-query]: https://github.com/senecajs/seneca-store-query
[postgresqlorg]: http://www.postgresql.org/
[seneca]: http://senecajs.org/
[nodepg]: https://github.com/brianc/node-postgres
[Senecajs org]: https://github.com/senecajs/
[Coveralls]: https://coveralls.io/github/senecajs/seneca-postgres-store?branch=master
[BadgeCoveralls]: https://coveralls.io/repos/github/senecajs/seneca-postgres-store/badge.svg?branch=master
[![npm version][npm-badge]][npm-url]
[![Build Status][travis-badge]][travis-url]
[![Dependency Status][david-badge]][david-url]
[![Coveralls][BadgeCoveralls]][Coveralls]
[![Gitter][gitter-badge]][gitter-url]

| ![Voxgig](https://www.voxgig.com/res/img/vgt01r.png) | This open source module is sponsored and supported by [Voxgig](https://www.voxgig.com). |
|---|---|
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "seneca-postgres-store",
"name": "@seneca/postgres-store",
"version": "2.4.0",
"description": "Seneca data store plugin for PostgreSQL",
"main": "postgresql-store.js",
Expand Down Expand Up @@ -58,7 +58,6 @@
"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"` && echo TAG: v$REPO_VERSION && git commit -a -m v$REPO_VERSION && git push && git tag v$REPO_VERSION && git push --tags;",
"repo-publish": "npm run clean && npm i --registry=https://registry.npmjs.org && npm run repo-publish-quick",
"repo-publish-quick": "npm test && npm run repo-tag && npm publish --access public --registry=https://registry.npmjs.org"

},
"dependencies": {
"pg": "8.9.0",
Expand All @@ -75,4 +74,4 @@
"seneca-entity": "20.0.1",
"seneca-store-test": "5.2.0"
}
}
}