• Stars
    star
    300
  • Rank 138,870 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reactive PostgreSQL for Meteor

numtel:pg Build Status

Reactive PostgreSQL for Meteor

Provides Meteor integration of the pg-live-select NPM module, bringing reactive SELECT statement result sets from PostgreSQL >= 9.3.

If you do not have PostgreSQL server already installed, you may use the numtel:pg-server Meteor Package to bundle the PostgreSQL server directly to your Meteor application.

Server Implements

This package provides the LivePg class as defined in the pg-live-select NPM package.

Also exposed on the server is the pg object as defined in the node-postgres NPM package (useful for other operations like INSERT and UPDATE).

LivePg.prototype.select()

In this Meteor package, the SelectHandle object returned by the select() method is modified to act as a cursor that can be published.

var liveDb = new LivePg(CONNECTION_STRING, CHANNEL);

Meteor.publish('allPlayers', function(){
  return liveDb.select('SELECT * FROM players ORDER BY score DESC');
});

Client/Server Implements

PgSubscription([connection,] name, [args...])

Constructor for subscribing to a published select statement. No extra call to Meteor.subscribe() is required. Specify the name of the subscription along with any arguments.

The first argument, connection, is optional. If connecting to a different Meteor server, pass the DDP connection object in this first argument. If not specified, the first argument becomes the name of the subscription (string) and the default Meteor server connection will be used.

The prototype inherits from Array and is extended with the following methods:

Name Description
change([args...]) Change the subscription's arguments. Publication name and connection are preserved.
addEventListener(eventName, listener) Bind a listener function to this subscription
removeEventListener(eventName) Remove listener functions from an event queue
dispatchEvent(eventName, [args...]) Call the listeners for a given event, returns boolean
depend() Call from inside of a Template helper function to ensure reactive updates
reactive() Same as depend() except returns self
changed() Signal new data in the subscription
ready() Return boolean value corresponding to subscription fully loaded
stop() Stop updates for this subscription

Notes:

  • changed() is automatically called when the query updates and is most likely to only be called manually from a method stub on the client.
  • Event listener methods are similar to native methods. For example, if an event listener returns false exactly, it will halt listeners of the same event that have been added previously. A few differences do exist though to make usage easier in this context:
    • The event name may also contain an identifier suffix using dot namespacing (e.g. update.myEvent) to allow removing/dispatching only a subset of listeners.
    • removeEventListener() and dispatchEvent() both refer to listeners by name only. Regular expessions allowed.
    • useCapture argument is not available.

Event Types

Name Listener Arguments Description
update diff, data New change, before data update
updated diff, data New change, after data update
reset msg Subscription reset (most likely due to code-push), before update

Closing connections between hot code-pushes

With Meteor's hot code-push feature, new triggers and functions on database server are created with each restart. In order to remove old items, a handler to your application process's SIGTERM signal event must be added that calls the cleanup() method on each LivePg instance in your application. Also, a handler for SIGINT can be used to close connections on exit.

On the server-side of your application, add event handlers like this:

var liveDb = new LivePg(CONNECTION_STRING, CHANNEL);

var closeAndExit = function() {
  // Call process.exit() as callback
  liveDb.cleanup(process.exit);
};

// Close connections on hot code push
process.on('SIGTERM', closeAndExit);
// Close connections on exit (ctrl + c)
process.on('SIGINT', closeAndExit);

Tests / Benchmarks

The test suite does not require a separate Postgres server installation as it uses the numtel:pg-server package to run the tests.

The database connection settings must be configured in test/settings/local.json.

The database specified should be an empty database with no tables because the tests will create and delete tables as needed.

# Install Meteor
$ curl -L https://install.meteor.com/ | /bin/sh

# Clone Repository
$ git clone https://github.com/numtel/meteor-pg.git
$ cd meteor-pg

# Optionally, configure port and data dir in test/settings/test.pg.json.
# If changing port, keep port value updated in test/index.es6 as well.

# Test database will be created in dbtest directory.

# Run test server
$ meteor test-packages ./

License

MIT

More Repositories

1

meteor-mysql

Reactive MySQL for Meteor
JavaScript
343
star
2

mysql-live-select

NPM Package to provide events on updated MySQL SELECT result sets
JavaScript
87
star
3

reactive-mysql-example

Example of reactive data using mysql-live-select with Express, SockJS, and React
JavaScript
51
star
4

meteor-webcomponent

WebComponent integration for Meteor templates
CoffeeScript
38
star
5

meteor-component-example

Load templates on-demand using miro:preloader and numtel:publicsources
JavaScript
38
star
6

meteor-mysql-server

Package to run MySQL server inside your Meteor app
JavaScript
34
star
7

meteor-mysql-leaderboard

Exploring methods of using mysql reactively
CSS
30
star
8

meteor-lazy-bundles

Create bundles for lazy-loading components, optionally with authentication
JavaScript
29
star
9

nano-webgl-pow

WebGL2 Nano Currency Proof of Work Generation
JavaScript
26
star
10

progress-promise

Promise subclass with mechanism to report progress before resolving
JavaScript
24
star
11

meteor-privatesources

Create bundles for lazy-loading components, with authentication
JavaScript
20
star
12

node-nano-node

Nano currency (Formerly raiblocks) partial node for node.js
JavaScript
20
star
13

bitcoin-tx

Facebook App to Send Bitcoins to your Friends
PHP
15
star
14

rai-paper-wallet

Nano Currency (RaiBlocks) paper wallet generator
JavaScript
13
star
15

meteor-publicsources

Create bundles in public directory for lazy-loading components
JavaScript
13
star
16

meteor-leaderboard-tinytest

Use Tinytest to test a Meteor application without any extra packages
CSS
12
star
17

open-nano-wallet

Nano (RaiBlocks) light wallet
JavaScript
11
star
18

meteor-pg-leaderboard

Meteor Leaderboard Example with PostgreSQL backend
CSS
10
star
19

meteor-cfs-image-resize

Resize images in CollectionFS using Jimp
JavaScript
9
star
20

meteor-pg-server

Package to run PostgreSQL server inside your Meteor app
JavaScript
8
star
21

tinytest-in-app

Use Tinytest to test a Meteor application
CoffeeScript
8
star
22

shadowstyles

Isolated CSS for simulated Shadow DOM
JavaScript
8
star
23

phantomjs-persistent-server

PhantomJS Persistent Server Meteor Package
JavaScript
8
star
24

meteor-template-from-string

Create Meteor template from String
JavaScript
7
star
25

meteor-benchmark-packages

Perform benchmarks while testing your Meteor packages
JavaScript
6
star
26

nano-mass-tx

Send transactions back and forth to load the network
JavaScript
6
star
27

snorb

WebGL Terrain Editor
JavaScript
5
star
28

popular_demand

A moderated, threaded discussion board using Django with crowdfunding functionality through Stripe
Python
4
star
29

sails-postgresql-live-select

SailsJS Connection adapter for live real time PostgreSQL result set updates
JavaScript
4
star
30

s3-range-zip

Load individual files from zip files on S3 using range
JavaScript
3
star
31

tinytest-fixture-account

Tinytest fixture to create a user account for client-side tests
CoffeeScript
3
star
32

pg-server-9.4-linux-x64

PostgreSQL Server 9.4 for Linux x86 64-bit NPM Package
PLpgSQL
3
star
33

sails-mysql-live-select

SailsJS Connection adapter for live real time MySQL result set updates
JavaScript
3
star
34

webgl-isometric

Orthographic (not isometric) view game engine from Tiled maps
JavaScript
3
star
35

colorswap.js

Instantly replace colors on your page!
JavaScript
3
star
36

lwned

Partially collateralized loans
JavaScript
2
star
37

meteor-es6-proxy

Iron:Router Plugin for rendering transpiled ES6 -> ES5 to the client
JavaScript
2
star
38

css-unit-test

CSS Unit Test Application (made with Meteor)
JavaScript
2
star
39

serverobject

ServerObject Meteor Package
JavaScript
2
star
40

velocity-tinytest

Use Tinytest with Velocity
CoffeeScript
2
star
41

node-pg-mem-test

JavaScript
2
star
42

salamander

Modular PHP Framework
JavaScript
2
star
43

mysql-server-5.6-linux-x64

MySQL Server 5.6 for Linux x86 64-bit as NPM package
PLpgSQL
2
star
44

beach-report-lite

Lightweight version of beachreportcard.org
JavaScript
1
star
45

meteor-subscribed-array

JavaScript
1
star
46

xrb-light-wallet

Redirect for old repo
HTML
1
star
47

sticky-contracts

JavaScript
1
star
48

meteor-colorswap

Meteor Package for colorswap.js
JavaScript
1
star
49

css-unit-test-core

Core [Meteor] Package for SteezTest.me
JavaScript
1
star
50

mysql-server-5.6-osx-x64

MySQL Server 5.6 for Mac OSX x86 64-bit as NPM package
PLpgSQL
1
star
51

newgeocities

Publish websites on the blockchain
JavaScript
1
star
52

infinite-browser

JavaScript
1
star
53

optimeme

No-code NFT deployments
Solidity
1
star
54

zk-group-decryptable

An adaptation of Semaphore v4 with optional decryptability
Solidity
1
star
55

three-js-lathe-twist

Three.js Twisted Lathe Geometry Example
JavaScript
1
star
56

clonk-me

On chain messaging
JavaScript
1
star
57

blockscout-urls

List of Blockscout explorer URLs keyed by chain id
JavaScript
1
star
58

sails-postgresql-live-select-chat-example

SailsJS example application with real time PostgreSQL result sets
JavaScript
1
star