-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Manipulating the database
olibou edited this page Apr 27, 2013
·
2 revisions
var db = require('ep_etherpad-lite/node/db/DB').db
db.get("record_key", function(err, record_value){
// do something
});
// Replace data value if the record already exists or create a new record with this key
db.set("record_key", data);
// Add a subvalue to an existing record data
db.setSub("record_key", ["sub_key"], value);
{"colorId":"#79d9d9","name":"tutti","timestamp":1364832712430,"padIDs":{"mypad":1}}
db.setSub("record_key", ["email"], "[email protected]");
{"colorId":"#79d9d9","name":"tutti","timestamp":1364832712430,"padIDs":{"mypad":1},"email":"[email protected]"}
By default, the results from a db.get are cached (set initially to 1000).
In some case, it's not what you want.
To remove the caching system for requests, you can set the 'caching' option to 0
db['dbSettings'].cache = 0;
Here is a small code to migrate dirty.db to mysql ...
#!/usr/bin/perl
use strict;
use DBI;
my $dbh = DBI->connect("DBI:mysql:database=etherpad;host=localhost", "yourMysqlId", "yourMysqlPasswd",) or die;
$dbh->prepare("TRUNCATE TABLE store")->execute();
$dbh->prepare("SET CHARACTER SET utf8")->execute();
open(F,"var/dirty.db") or die;
while (<F>) {
if (m|\{\"key\":\"(.*)\",\"val\":(.*)\}|) {
my ($k,$v) = ($1,$2);
my $sth = $dbh->prepare("SELECT `key` FROM store WHERE `key` = ?") or die;
$sth->execute($k) or die;
my @a = $sth->fetchrow();
if ($a[0]) {
$sth = $dbh->prepare("UPDATE store set `value` = ? WHERE `key` = ?") or die;
$sth->execute($v,$k) or die;
} else {
$sth = $dbh->prepare("INSERT INTO store (`key`,`value`) VALUES (?,?)") or die;
$sth->execute($k,$v) or die;
}
} else {
die "Err!\n";
}
}
close F;
- Docs
- Translating
- HTTP API
- Plugin framework (API hooks)
- Plugins (available)
- Plugins (list)
- Plugins (wishlist)
- Etherpad URIs / URLs to specific resources IE export
- Etherpad Full data export
- Introduction to the source
- Release Procedure
- Etherpad Developer guidelines
- Project to-do list
- Changeset Library documentation
- Alternative Etherpad-Clients
- Contribution guidelines
- Installing Etherpad
- Deploying Etherpad as a service
- Deploying Etherpad on CloudFoundry
- Deploying Etherpad on Heroku
- Running Etherpad on Phusion Passenger
- Putting Etherpad behind a reverse Proxy (HTTPS/SSL)
- How to setup Etherpad on Ubuntu 12.04 using Ansible
- Migrating from old Etherpad to Etherpad
- Using Etherpad with MySQL
- Customizing the Etherpad web interface
- Enable import/export functionality with AbiWord
- Getting a list of all pads
- Providing encrypted web access to Etherpad using SSL certificates
- Optimizing Etherpad performance including faster page loads
- Getting to know the tools and scripts in the Etherpad /bin/ folder
- Embedding a pad using the jQuery plugin
- Using Embed Parameters
- Integrating Etherpad in a third party app (Drupal, MediaWiki, WordPress, Atlassian, PmWiki)
- HTTP API client libraries