npm modules (sequelize) in a couchapp

120 views
Skip to first unread message

Emil Stenberg

unread,
Nov 5, 2013, 3:56:21 PM11/5/13
to ka...@googlegroups.com
I want to replicate changes to a sql database, (Or I do not WANT to, but it's a requirement in my current project...)
I am thinking about building a couchapp that listen to changes on the database and then executes some sql.

There are some orm:s for node, for instance 'sequelize'. Is it possible to use it inside a couchapp? Of course this would be used to access another database, not couchdb.

Or is there another, easier way to do this?

Any help is appreciated!

Kind regards
Emil

Benjamin Young

unread,
Nov 5, 2013, 4:02:46 PM11/5/13
to ka...@googlegroups.com, Emil Stenberg
If you could expose an HTTP API matching the same endpoints as CouchDB
uses for replication, that could work:
http://docs.couchdb.org/en/latest/replication/intro.html

Let me know if you start an experiment on it.

You'd have to keep a sequential of *all* changes to the database (that
you want to replicate) *and* one per "document" (afaik). "Document"
might not (likely won't) map directly to any single table, but probably
an aggregate of table content.

Lots of work...sadly...but not impossible.
> --
> You received this message because you are subscribed to the Google
> Groups "kanso" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to kanso+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Emil Stenberg

unread,
Nov 6, 2013, 2:42:05 AM11/6/13
to ka...@googlegroups.com
Thank you, that's a much better idea!
Couch (as far as I've understood) only uses two paths on the target database when replicating;
One to get the missing revisions, and that accepts posting of a json array of documents.
I hope that by keeping my json docs flat, I might be able to have the same structure in the sql database.
My current plan is to build a node module that behaves like a target couchdb when replicating, but persists in a rdbm. I'll let you know how it goes.

Hopefully an easy job ;)

Kevin McGee

unread,
Nov 6, 2013, 4:55:10 PM11/6/13
to ka...@googlegroups.com
Too bad you guys went off to solve the actual problem leaving the original question unanswered:
  • Is it possible to use it (meaning an arbitrary NPM module) inside a couchapp?
I was wondering abut that...

KJM

Benjamin Young

unread,
Dec 19, 2013, 4:21:31 PM12/19/13
to ka...@googlegroups.com
It depends on what you mean by "inside." Projects like browserify.org make (some) npm modules usable in the browser, so you could use them in front-end development. NPM modules also work well during development--minification, etc.

CouchDB does support CommonJS requires, and many/most CommonJS compatible libraries do work in CouchDB:
http://wiki.apache.org/couchdb/CommonJS_Modules

Moment.js (for one) works just fine. Here's some example code:
https://github.com/cloudant-labs/Spellbook/tree/master/date-arrays

However, CouchDB uses SpiderMonkey (currently) under the hood, so there's no V8 nor node.js "lower level" stuff available. It also doesn't provide the DOM API, XHR, or other "heavier" APIs. Many of the NPM modules are focused on building servers, and those would be far outside of the scope of what the JavaScript that runs *inside* CouchDB is intended to do.

There is an experimental node.js-based view server available out there, but I've no idea what/if any additional functionality that will bring to the table--or if it's just going to swap out SpiderMonkey for V8. If you find out, I'd love to know! :)

Hope something in there was helpful. :)

Later,
Benjamin
--

Eric Drechsel

unread,
Jan 22, 2014, 11:24:59 PM1/22/14
to ka...@googlegroups.com
I'm also looking for an answer to this question.

It would be great if a tool like browserify could be used to bundle an NPM dependency tree into a commonjs module ready to use in CouchDB views, etc.

It seems like this should be fairly simple to implement. After all, NPM modules conform to the CommonJS module specification (v1.0, not 1.1).
Reply all
Reply to author
Forward
0 new messages