Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #216

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Dev #216

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ dist: venv/.dist
source venv/bin/activate
$(PYTHON) -m build

.PHONY: check.publish
check.publish: dist
source venv/bin/activate
twine check dist/*
Expand Down
10 changes: 6 additions & 4 deletions docs/source/defining-sql-queries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ Then the generated function expects two named parameters:
res = queries.with_params(name="Calvin", x=(1+1j))
# => (6, 2.0)

Parameters Declarations
-----------------------
Parameter Declarations
----------------------

Query parameters names may be declared in parentheses just after the method name.
Query parameter names may be declared in parentheses just after the method name.

.. literalinclude:: ../../tests/blogdb/sql/blogs/blogs.sql
:language: sql
Expand Down Expand Up @@ -149,7 +149,7 @@ modifications to database rows without a necessary return value.

.. literalinclude:: ../../tests/blogdb/sql/blogs/blogs.sql
:language: sql
:lines: 64-66, 31,34
:lines: 64-66,32,34

The methods generated are:

Expand Down Expand Up @@ -243,3 +243,5 @@ An example usecase is using data definition statements like create table in orde

queries = aiosql.from_path("create_schema.sql", "sqlite3")
queries.create_table_blogs(conn)

Note: SQL scripts do not accept parameters.
7 changes: 7 additions & 0 deletions docs/source/versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ TODO
- test with nogil once available in GitHub CI.
- test with py 3.14 once available in GitHub CI (pydantic/rust issue for now).

? on ?
------

- improve documentation with declared parameters in examples.
- homogeneise test consistency wrt attribute and parameter names.
- fix doc typos.

13.0 on 2024-11-10
------------------

Expand Down
14 changes: 7 additions & 7 deletions tests/blogdb/sql/blogs/blogs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DROP TABLE IF EXISTS blogs;
-- name: drop-table-comments#
DROP TABLE IF EXISTS comments;

-- name: get-all-blogs
-- name: get-all-blogs()
-- Fetch all fields for every blog in the database.
select * from blogs;

Expand All @@ -25,11 +25,11 @@ insert into blogs (
values (
:userid,
:title,
:contents,
:content,
:published
);

-- name: remove-blog!
-- name: remove-blog(blogid)!
-- Remove a blog from the database
delete from blogs where blogid = :blogid;

Expand Down Expand Up @@ -61,13 +61,13 @@ select blogid, title from blogs where blogid = :blogid;
-- name: with-params^
select length(:name), :x.real + x.imaj;

-- name: new-blog!
-- name: new-blog(userid, title, content)!
insert into blogs (userid, title, content)
values (:userid, :title, :contents);
values (:userid, :title, :content);

-- name: publish-new-blog$
-- name: publish-new-blog(userid, title, content)$
insert into blogs (userid, title, content)
values (:userid, :title, :contents)
values (:userid, :title, :content)
returning blogid;

-- name: add_many_blogs*!
Expand Down
4 changes: 2 additions & 2 deletions tests/blogdb/sql/blogs/ms/blogs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ output inserted.blogid, inserted.title
values (
:userid,
:title,
:contents,
:content,
:published
);

Expand All @@ -62,4 +62,4 @@ where 0 = 1;
-- name: bulk-publish*!
-- Insert many blogs at once
insert into blogs (userid, title, content, published)
values (:userid, :title, :contents, :published);
values (:userid, :title, :content, :published);
4 changes: 2 additions & 2 deletions tests/blogdb/sql/blogs/pg/blogs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ insert into blogs (
values (
:userid,
:title,
:contents,
:content,
:published
)
returning blogid, title;
Expand All @@ -50,4 +50,4 @@ where false;
-- name: bulk-publish*!
-- Insert many blogs at once
insert into blogs (userid, title, content, published)
values (:userid, :title, :contents, :published);
values (:userid, :title, :content, :published);
4 changes: 2 additions & 2 deletions tests/blogdb/sql/users/users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-- Get all user records
select * from users order by 1;

-- name: get-by-username^
-- name: get-by-username(username)^
select userid,
username,
firstname,
Expand All @@ -27,7 +27,7 @@ order by username asc;
select * from users order by username asc;


-- name: get-count$
-- name: get-count()$
-- Get number of users
select count(*) as cnt from users;

Expand Down
10 changes: 5 additions & 5 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ def _insert_blogs(todate):
{
"userid": 2,
"title": "Blog Part 1",
"contents": "content - 1",
"content": "content - 1",
"published": todate(2018, 12, 4),
},
{
"userid": 2,
"title": "Blog Part 2",
"contents": "content - 2",
"content": "content - 2",
"published": todate(2018, 12, 5),
},
{
"userid": 2,
"title": "Blog Part 3",
"contents": "content - 3",
"content": "content - 3",
"published": todate(2018, 12, 6),
},
]
Expand Down Expand Up @@ -278,7 +278,7 @@ def run_insert_returning(conn, queries, date):
conn,
userid=2,
title="My first blog",
contents="Hello, World!",
content="Hello, World!",
published=date(2018, 12, 4),
)

Expand Down Expand Up @@ -538,7 +538,7 @@ async def run_async_insert_returning(aconn, queries, date):
aconn,
userid=2,
title="My first blog",
contents="Hello, World!",
content="Hello, World!",
published=date(2018, 12, 4),
)

Expand Down