summaryrefslogtreecommitdiff
path: root/examples/18-database/output
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-12-05 21:46:47 +0000
committerMichael Williamson <mike@zwobble.org>2026-12-05 21:46:47 +0000
commit959506c587362d53bdcc0a102966d01d9b41d296 (patch)
tree4e104e23d02cbc6c82a2bcfbe746967fc1361a31 /examples/18-database/output
parentd536d0535af4a3b88ec356a6d1b561d6942334f2 (diff)
Generate SQL for queries with paramsmain
Diffstat (limited to 'examples/18-database/output')
-rw-r--r--examples/18-database/output/sqlite3/scripts/data/authorsByName.sql8
-rw-r--r--examples/18-database/output/sqlite3/test.py18
2 files changed, 26 insertions, 0 deletions
diff --git a/examples/18-database/output/sqlite3/scripts/data/authorsByName.sql b/examples/18-database/output/sqlite3/scripts/data/authorsByName.sql
new file mode 100644
index 0000000..e621470
--- /dev/null
+++ b/examples/18-database/output/sqlite3/scripts/data/authorsByName.sql
@@ -0,0 +1,8 @@
+-- Generated by hobgoblin.
+
+SELECT
+ id AS id,
+ name AS name
+FROM authors
+WHERE authors.name == ?1
+ORDER BY id;
diff --git a/examples/18-database/output/sqlite3/test.py b/examples/18-database/output/sqlite3/test.py
index c985de2..aea7ab3 100644
--- a/examples/18-database/output/sqlite3/test.py
+++ b/examples/18-database/output/sqlite3/test.py
@@ -57,6 +57,24 @@ class DataTestCase(unittest.TestCase):
self.assertEqual(rows, [(2, "Bob")])
+ def test_query_authors_by_name(self):
+ create_script = self._read_script("Data")
+
+ connection = sqlite3.connect(":memory:", autocommit=False)
+ cursor = connection.cursor()
+ cursor.executescript(create_script)
+ connection.commit()
+
+ cursor.execute("INSERT INTO authors VALUES (1, 'Alice')")
+ cursor.execute("INSERT INTO authors VALUES (2, 'Bob')")
+ cursor.execute("INSERT INTO authors VALUES (3, 'Carol')")
+
+ select_query = self._read_script("authorsByName")
+ cursor.execute(select_query, ("Bob",))
+ rows = cursor.fetchall()
+
+ self.assertEqual(rows, [(2, "Bob")])
+
def _read_script(self, name):
sql_script_path = os.path.join(os.path.dirname(__file__), "scripts/data", name + ".sql")
with open(sql_script_path, "rt", encoding="utf-8") as sql_script_file: