Permalink
Browse files

merge save updates from master

  • Loading branch information...
2 parents a03492b + cfb3ca7 commit 98a3267478365d64c1239de73236d359ca5597df @JerrySievert committed Jan 4, 2013
Showing with 17 additions and 5 deletions.
  1. +0 −4 create_collection.sql
  2. +17 −1 save.sql
@@ -13,22 +13,18 @@ boolean AS $$
var plan3 = plv8.prepare('CREATE SEQUENCE seq_col_' + collection);
var ret;
-
try {
plv8.subtransaction(function () {
plan1.execute([ collection ]);
plan2.execute([ ]);
plan3.execute([ ]);
-
ret = true;
});
} catch (err) {
ret = false;
}
-
plan1.free();
plan2.free();
plan3.free();
- return ret;
$$ LANGUAGE plv8 IMMUTABLE STRICT;
View
@@ -4,7 +4,23 @@ BOOLEAN AS $$
// if there is no id, naively assume an insert
if (id === undefined) {
- var seq = plv8.prepare("SELECT nextval('seq_col_" + collection + "') AS id");
+ var seq;
+ try
+ {
+ plv8.subtransaction(function(){
+ seq = plv8.prepare("SELECT nextval('seq_col_" + collection + "') AS id");
+ });
+ }
+ catch(err)
+ {
+ if (err='Error: relation "seq_col_' + collection + '" does not exist')
+ {
+ var create_collection = plv8.find_function("create_collection");
+ res = create_collection(collection);
+ seq = plv8.prepare("SELECT nextval('seq_col_" + collection + "') AS id");
+ }
+ }
+
var rows = seq.execute([ ]);
id = rows[0].id;

0 comments on commit 98a3267

Please sign in to comment.