Comparing version 10.113.2 to 10.114.0
@@ -277,3 +277,4 @@ (function() { | ||
fields: null, | ||
exclude: null | ||
exclude: null, | ||
returning: null | ||
} | ||
@@ -280,0 +281,0 @@ } |
@@ -83,3 +83,3 @@ (function() { | ||
case 'text': | ||
R.push(`on conflict ${cfg.on_conflict};`); | ||
R.push(`on conflict ${cfg.on_conflict}`); | ||
break; | ||
@@ -98,3 +98,2 @@ case 'object': | ||
})()).join(', ')); | ||
R.push(";"); | ||
break; | ||
@@ -105,4 +104,8 @@ default: | ||
} else { | ||
R.push(" );"); | ||
R.push(" )"); | ||
} | ||
if (cfg.returning != null) { | ||
R.push(` returning ${cfg.returning}`); | ||
} | ||
R.push(";"); | ||
return R.join(''); | ||
@@ -109,0 +112,0 @@ } |
@@ -249,2 +249,5 @@ (function() { | ||
}, | ||
"@isa_optional.nonempty_text x.returning": function(x) { | ||
return this.isa_optional.nonempty_text(x.returning); | ||
}, | ||
"x.on_conflict is an optional nonempty_text or suitable object": function(x) { | ||
@@ -251,0 +254,0 @@ if (x.on_conflict == null) { |
{ | ||
"name": "dbay", | ||
"version": "10.113.2", | ||
"version": "10.114.0", | ||
"description": "In-Process, In-Memory & File-Based Relational Data Processing with SQLite, BetterSQLite3", | ||
"main": "lib/main.js", | ||
"scripts": { | ||
"build": "coffee --map -o lib -c src", | ||
"test": "echo see 'https://github.com/loveencounterflow/hengist/tree/master/dev/dbay'", | ||
"preinstall": "./build-sqlite3" | ||
}, | ||
"repository": { | ||
@@ -27,8 +32,3 @@ "type": "git", | ||
"intertype": "7.6.7" | ||
}, | ||
"scripts": { | ||
"build": "coffee --map -o lib -c src", | ||
"test": "echo see 'https://github.com/loveencounterflow/hengist/tree/master/dev/dbay'", | ||
"preinstall": "./build-sqlite3" | ||
} | ||
} | ||
} |
@@ -32,2 +32,3 @@ | ||
- [Insert Statement Generation](#insert-statement-generation) | ||
- [Insert Statements with a `returning` Clause](#insert-statements-with-a-returning-clause) | ||
- [Random](#random) | ||
@@ -429,3 +430,25 @@ - [Note on Package Structure](#note-on-package-structure) | ||
#### Insert Statements with a `returning` Clause | ||
It is sometimes handy to have `insert` statements that return a useful value. Here's a toy example | ||
that demonstrates how one can have a table with generated columns: | ||
```coffee | ||
db SQL""" | ||
create table xy ( | ||
a integer not null primary key, | ||
b text not null, | ||
c text generated always as ( '+' || b || '+' ) );""" | ||
insert_into_xy_sql = db.create_insert { into: 'xy', on_conflict: SQL"do nothing", returning: '*', } | ||
# -> 'insert into "main"."xy" ( "a", "b" ) values ( $a, $b ) on conflict do nothing returning *;' | ||
db.single_row insert_into_xy_sql, { a: 1, b: 'any', } # -> { a: 1, b: 'any', c: '+any+' } | ||
db.single_row insert_into_xy_sql, { a: 2, b: 'duh', } # -> { a: 2, b: 'duh', c: '+duh+' } | ||
db.single_row insert_into_xy_sql, { a: 3, b: 'foo', } # -> { a: 3, b: 'foo', c: '+foo+' } | ||
``` | ||
Generally, the `returning` clause must be defined by a non-empty string that is valid SQL for the position | ||
after `returning` and the end of the statement. A star `*` will return the entire row that has been | ||
inserted; we here use `db.single_row()` to eschew the result iterator that would be returned by default. | ||
------------------------------------------------------------------------------------------------------------ | ||
@@ -514,2 +537,3 @@ | ||
* **[–]** `db.rollback()` | ||
* **[–]** allow to use sets with `sql.V()` | ||
@@ -516,0 +540,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11987452
1723
540