|
1 | 1 | # flamebase-database-node |
2 | | -Realtime database for Node.js |
| 2 | + |
| 3 | +Real time JSON database server-side. |
| 4 | + |
| 5 | +### Usage |
| 6 | + |
| 7 | +```javascript |
| 8 | +var FlamebaseDatabase = require("flamebase-database-node"); |
| 9 | + |
| 10 | +var database = "myDatabase"; // name of db |
| 11 | +var path = "cars/"; // path to JSON reference |
| 12 | + |
| 13 | +/** |
| 14 | +* db reference |
| 15 | +*/ |
| 16 | +var FD = new FlamebaseDatabase(database, path); |
| 17 | +var queue = FD.getQueue(); |
| 18 | + |
| 19 | +/** |
| 20 | +* load JSON reference on FD.ref |
| 21 | +*/ |
| 22 | +FD.syncFromDatabase(); |
| 23 | + |
| 24 | +var object = this; |
| 25 | + |
| 26 | +/** |
| 27 | +* devices to keep up to date |
| 28 | +*/ |
| 29 | +var devices = []; |
| 30 | + |
| 31 | +var deviceA = {}; |
| 32 | +deviceA.token = "TOKEN_DEVICE_A"; |
| 33 | +deviceA.os = FC.OS.ANDROID; |
| 34 | + |
| 35 | +devices.push(deviceA); |
| 36 | + |
| 37 | + |
| 38 | +// ################ ios lib not ready yet |
| 39 | +var deviceB = {}; |
| 40 | +deviceB.token = "TOKEN_DEVICE_B"; |
| 41 | +deviceB.os = FC.OS.IOS; |
| 42 | + |
| 43 | +devices.push(deviceB); |
| 44 | + |
| 45 | +/** |
| 46 | +* config db synchronization |
| 47 | +*/ |
| 48 | +this.setConfig = function() { |
| 49 | + |
| 50 | + /** |
| 51 | + * config for db synchronization (server - client) |
| 52 | + * @type {{}} |
| 53 | + */ |
| 54 | + var config = {}; |
| 55 | + |
| 56 | + /** |
| 57 | + * server notification key |
| 58 | + */ |
| 59 | + config.APIKey = function() { |
| 60 | + return "YOUR_FCM_PUSH_KEY"; // server key - FCM |
| 61 | + }; |
| 62 | + |
| 63 | + /** |
| 64 | + * devices to keep up to date |
| 65 | + */ |
| 66 | + config.devices = function() { |
| 67 | + return devices; |
| 68 | + }; |
| 69 | + |
| 70 | + /** |
| 71 | + * custom tag for sync |
| 72 | + * - used in android client |
| 73 | + */ |
| 74 | + config.tag = function() { |
| 75 | + return "user_sync"; |
| 76 | + }; |
| 77 | + |
| 78 | + /** |
| 79 | + * custom id for database reference |
| 80 | + * - used in android client |
| 81 | + */ |
| 82 | + config.referenceId = function() { |
| 83 | + return "CUSTOM_ID"; |
| 84 | + }; |
| 85 | + |
| 86 | + /** |
| 87 | + * custom notification info to send when database reference changes. |
| 88 | + * set null if not needed |
| 89 | + * |
| 90 | + * - used in android client |
| 91 | + * |
| 92 | + * config.notification = null; |
| 93 | + */ |
| 94 | + config.notification = function() { |
| 95 | + return { |
| 96 | + type: "custom_type", |
| 97 | + name: object.FD.ref.name, |
| 98 | + image: object.FD.ref.photoURL |
| 99 | + } |
| 100 | + }; |
| 101 | + |
| 102 | + /** |
| 103 | + * sync config |
| 104 | + */ |
| 105 | + FD.setSyncConfig(config); |
| 106 | + |
| 107 | + /** |
| 108 | + * enable debug logs |
| 109 | + */ |
| 110 | + FD.debug(true); |
| 111 | +}; |
| 112 | +``` |
0 commit comments