AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.04k stars 659 forks source link

Can I UPDATE nested property of row? #593

Open a-gorbunov opened 8 years ago

a-gorbunov commented 8 years ago

Example:

alasql("INSERT INTO [Test] VALUES ?", {a: 1, b: {c: 2}})

Can I update property b.c of inserted object in UPDATE statement? I mean somthing like

alasql("UPDATE [Test] SET [b->c] = ? WHERE a = 1", 3)

Currenly I'm using SELECT + UPDATE of top-level property.

agershun commented 8 years ago

Hm. Unfortunately, not now... But I think that there is a way...

We can easily extend syntax to:

alasql("UPDATE [Test] SET b->c = ? WHERE a = 1", 3)
//or for 'non-arrow' syntax
alasql("UPDATE [Test] SET b.c = ? WHERE a = 1", 3)

The only problems is time...

What you can do right now... you can register user-defined function:

alasql.fn.modifyb = function(b,v) {
    b.c = v;
    return b;
};
alasql("UPDATE [Test] SET b = modifyb(b,?) WHERE a = 1", 3)