I am tasked with using Apache Metamodel with CouchDB and Node.js. Despite trying it out in google, i could not get an example for the same. Th examples found seem to be more suited for RDBMS! Can i get an example to connect to couchdb, list all dbs, fetch a document and insert document and attachments?
Asked
Active
Viewed 127 times
1 Answers
0
Assuming you have documents a la this one:
{
"name": "John Doe",
"address:" {
"street": "21 3rd street"
},
"age": 42
}
Then you could query it like this:
CouchDbDataContext dc = ...;
DataSet ds = dc.query().from("my_database").select("name", "address", "age").execute();
while (ds.next()) {
Row r = ds.getRow();
String name = (String) r.getValue(0);
Map<String,?> address = (Map<String, ?>) r.getValue(1);
Number age = (Number) r.getValue(2);
}
ds.close();
And then to insert:
dc.executeUpdate(new UpdateScript() {
public void run(UpdateCallback cb) {
cb.insertInto("my_database").value("name", "Jane Doe").value("age", 43).execute();
}
});
Does it mostly work for RDBMSes? I wouldn't say so. But it is correct that Apache MetaModel attempts to make a unified view on all datastore types which includes mapping them to a table/column/row abstraction which is obviously an interpretation on top of something like CouchDB. The advantage is of course that the above code snippets could just as well work on a CSV file, a SQL table or any other datastore type that MetaModel supports.

Kasper Sørensen
- 321
- 2
- 6