From 281549e4cab07deb7fdd8fff6cdd13f0b2e4051e Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Fri, 1 Jan 2021 17:47:38 +0100 Subject: readme: document statement reuse Fixes #3 --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index dea6990..7f12093 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,27 @@ try stmt.exec({ See the section "Bind parameters and resultset rows" for more information on the types mapping rules. +## Reuse a statement + +You can reuse a statement by resetting it like this: +```zig +const query = + \\UPDATE foo SET salary = ? WHERE id = ? +; + +var stmt = try db.prepare(query); +defer stmt.deinit(); + +var id: usize = 0; +while (id < 20) : (id += 1) { + stmt.reset(); + try stmt.exec(.{ + .salary = 2000, + .id = id, + }); +} +``` + ## Reading data For queries which return data you have multiple options: -- cgit v1.2.3