node package manager
Painless code sharing. npm Orgs help your team discover, share, and reuse code. Create a free org »

zazler

Web platforms like node access directly to database. Natural thing to do. Zazler gives same feeling to Android and iPhone developers without hard work on backend.

Works with MySQL, PostgreSQL and SQLite. Provides JSON output and convienent way to see result in html.

In addition to query data Zazler supports insert/update/delete, authentication.

Here is brief example on server side:

// sqlite3 /tmp/my.db "create table a(id integer); insert into a values(1);"

var zazler = require("zazler");
zazler.db("db", "sqlite:///tmp/my.db", { read: "*" });
zazler.listen(80);

It allows to query like this:

curl http://localhost/db/a.json # gives whole table

Query data

  • ?where=id=10 − query by id
  • ?where=like(firstname,L)&L=J%25 − query by text matching. Notice how where expression is using variable L.
  • ?order=firstname − for ordering data.
  • ?limit=10 − for limiting output.
  • ?select=firstname,lastname − to select only some fields.
  • ?select=concat(firstname,spc,lastname)&spc=%20 − here SQL server does already more complicated work.
  • ?group=IDparty&select=IDparty,count(*) − to group data; you may want also use having parameter.

Limit database access

zazler.db( "example", "mysql://host/db", {

   // table and column level access limits
   // allows to query all columns from table1
   // and field1 and field2 from table2
   read: "table1 table2(field1 field2)",

   // for table `foo` `id > 100` is always added by Zazler
   // to where condition (addition to user condition from URL)
   filter: [
      { table: "foo",
        where: "id>100"
      } ]
});

read can use wildchars and exclusion: {read: "* -foo"} makes whole database is readable except table foo.

filter can also filter by authenticated user: {filter: { table: „users“, where: „id=auth.id“ }}.

More features

Zazler is precompiled nodejs extension.