Permalink
Browse files

Added sample mysql queries

  • Loading branch information...
1 parent bce2dc9 commit c50b06773311dcfa3f17cf777de32bdf31e4df8f @toddtreece committed Nov 8, 2011
Showing with 742 additions and 3 deletions.
  1. +674 −0 LICENSE
  2. +26 −3 README.md
  3. +13 −0 sql/install.sql
  4. +1 −0 sql/sample_init.sql
  5. +2 −0 sql/sample_query.sql
  6. +26 −0 sql/sample_trigger.sql
View
674 LICENSE

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,5 +1,22 @@
# lib_mysqludf_mongodb
+lib_mysqludf_mongodb
+Copyright 2011 Todd Treece
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
+
+## Hunh?
The goal of the project is to allow MySQL triggers to store data in MongoDB. By tracking MySQL changes (inserts/updates/deletes) in MongoDB, backing up system critical data will become faster and easier.
## Requirements
@@ -46,8 +63,14 @@ The goal of the project is to allow MySQL triggers to store data in MongoDB. By
CREATE FUNCTION mongodb_save RETURNS STRING SONAME "lib_mysqludf_mongodb.so";
## Usage
- -- connect to mongoDB
+ -- connecting to mongoDB:
-- this will only need to be called once
+ -- and can be placed in a mysql startup script.
+ --
+ -- in my.cnf add a line in the [mysqld] block
+ -- that points to your startup script.
+ -- i.e. init-file = /var/lib/mysql/init.sql
+
SELECT mongodb_connect("127.0.0.1", 27017);
-- sample query
@@ -64,8 +87,8 @@ The goal of the project is to allow MySQL triggers to store data in MongoDB. By
SET @save = (
SELECT mongodb_save(
- 'test.users.history' AS 'collection',
- NEW.id AS 'users_id',
+ 'history.users' AS 'collection',
+ NEW.id AS 'id',
NEW.username AS 'username',
NEW.firstname AS 'firstname',
NEW.lastname AS 'lastname',
View
@@ -0,0 +1,13 @@
+-- run this only after you have compiled
+-- and installed lib_mysqludf_mongodb.so
+
+USE mysql;
+DROP FUNCTION IF EXISTS mongodb_udf_version;
+DROP FUNCTION IF EXISTS mongodb_connect;
+DROP FUNCTION IF EXISTS mongodb_disconnect;
+DROP FUNCTION IF EXISTS mongodb_save;
+
+CREATE FUNCTION mongodb_udf_version RETURNS STRING SONAME "lib_mysqludf_mongodb.so";
+CREATE FUNCTION mongodb_connect RETURNS STRING SONAME "lib_mysqludf_mongodb.so";
+CREATE FUNCTION mongodb_disconnect RETURNS STRING SONAME "lib_mysqludf_mongodb.so";
+CREATE FUNCTION mongodb_save RETURNS STRING SONAME "lib_mysqludf_mongodb.so";
View
@@ -0,0 +1 @@
+SELECT mongodb_connect("127.0.0.1", 27017);
View
@@ -0,0 +1,2 @@
+-- the first argument will always be the mongodb collection name
+SELECT mongodb_save('test.customers' AS 'collection', firstname, lastname) FROM customers ORDER BY id DESC LIMIT 0,10;
View
@@ -0,0 +1,26 @@
+DELIMITER $$
+
+DROP TRIGGER IF EXISTS mongodb_update_trigger $$
+
+CREATE TRIGGER mongodb_update_trigger BEFORE UPDATE ON users
+
+ FOR EACH ROW BEGIN
+
+ SET @save = (
+ SELECT mongodb_save(
+ 'history.users' AS 'collection',
+ NEW.id AS 'id',
+ NEW.username AS 'username',
+ NEW.firstname AS 'firstname',
+ NEW.lastname AS 'lastname',
+ NEW.email AS 'email',
+ 'update' AS 'history_type',
+ NOW() AS 'timestamp'
+ )
+ );
+
+ END;
+
+$$
+
+DELIMITER ;

0 comments on commit c50b067

Please sign in to comment.