Skip to content

Commit 2baf5e4

Browse files
authored
Merge pull request #28 from AnswerDotAI/add-returning-to-writes
Add returning to basic writes (INSERT, UPDATE, DELETE)
2 parents e12d446 + 54bd1f2 commit 2baf5e4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sqlite_minutils/db.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,7 +2804,7 @@ def build_insert_queries_and_params(
28042804
# them since it ignores the resulting integrity errors
28052805
if not_null:
28062806
placeholders.extend(not_null)
2807-
sql = "INSERT OR IGNORE INTO [{table}]({cols}) VALUES({placeholders});".format(
2807+
sql = "INSERT OR IGNORE INTO [{table}]({cols}) VALUES({placeholders}) RETURNING *;".format(
28082808
table=self.name,
28092809
cols=", ".join(["[{}]".format(p) for p in placeholders]),
28102810
placeholders=", ".join(["?" for p in placeholders]),
@@ -2815,7 +2815,7 @@ def build_insert_queries_and_params(
28152815
# UPDATE [book] SET [name] = 'Programming' WHERE [id] = 1001;
28162816
set_cols = [col for col in all_columns if col not in pks]
28172817
if set_cols:
2818-
sql2 = "UPDATE [{table}] SET {pairs} WHERE {wheres}".format(
2818+
sql2 = "UPDATE [{table}] SET {pairs} WHERE {wheres} RETURNING *".format(
28192819
table=self.name,
28202820
pairs=", ".join(
28212821
"[{}] = {}".format(col, conversions.get(col, "?"))
@@ -2843,7 +2843,7 @@ def build_insert_queries_and_params(
28432843
elif ignore:
28442844
or_what = "OR IGNORE "
28452845
sql = """
2846-
INSERT {or_what}INTO [{table}] ({columns}) VALUES {rows};
2846+
INSERT {or_what}INTO [{table}] ({columns}) VALUES {rows} RETURNING *;
28472847
""".strip().format(
28482848
or_what=or_what,
28492849
table=self.name,

0 commit comments

Comments
 (0)