• Stars
    star
    343
  • Rank 123,371 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated almost 6 years ago

Reviews

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

Repository Details

Reactive MySQL for Meteor

numtel:mysql Build Status

Reactive MySQL for Meteor

Provides Meteor integration of the mysql-live-select NPM module, bringing reactive SELECT statement result sets from MySQL >= 5.1.15.

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

This documentation covers numtel:mysql >= 1.0.0. For older versions (0.1.0 - 0.1.14) that used the old difference calculator, see the the tree from this commit. Also see the old documentation for mysql-live-select that matches these older versions.

For the oldest versions (< 0.1.0) that included the trigger poll table that worked with MySQL < 5.1.15, see the old branch.

Server Implements

This package provides the LiveMysql class as defined in the mysql-live-select NPM package. Be sure to follow the installation instructions for configuring your MySQL server to output the binary log.

For operations other than SELECT, like UPDATE and INSERT, an active node-mysql connection is exposed on the LiveMysql.db property.

LiveMysql.prototype.select()

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

var liveDb = new LiveMysql(Meteor.settings.mysql);

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

Client/Server Implements

MysqlSubscription([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 Data has been updated according to the differences in the diff object.
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, a new connection the database server is requested with each restart. In order to close old connections, a handler to your application process's SIGTERM signal event must be added that calls the end() method on each LiveMysql 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 LiveMysql(Meteor.settings.mysql);

var closeAndExit = function() {
  liveDb.end();
  process.exit();
};

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

Tests / Benchmarks

A MySQL server configured to output the binary log in row mode is required to run the test suite.

The MySQL 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.

If you set the recreateDb value to true, the test suite will automatically create the database, allowing you to specify a database name that does not yet exist.

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

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

# Configure database settings in your favorite editor
# (an empty database is suggested)
$ ed test/settings/local.json

# Run test/benchmark server
$ meteor test-packages --settings test/settings/local.json ./

License

MIT

More Repositories

1

meteor-pg

Reactive PostgreSQL for Meteor
JavaScript
300
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