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

sqlite3 docs: extract row factory examples into row factory howto #96168

Closed
erlend-aasland opened this issue Aug 22, 2022 · 3 comments
Closed
Labels
docs Documentation in the Doc dir topic-sqlite3

Comments

@erlend-aasland
Copy link
Contributor

erlend-aasland commented Aug 22, 2022

There are several row factory examples scattered around the sqlite3 docs. Most of them in various places in the reference. Suggesting to extract them and create a row factory How-to Guide, in order to clean up the reference and reduce duplication of information.

@erlend-aasland erlend-aasland added docs Documentation in the Doc dir topic-sqlite3 labels Aug 22, 2022
@erlend-aasland erlend-aasland moved this to TODO: Docs in sqlite3 issues Aug 22, 2022
@erlend-aasland
Copy link
Contributor Author

cc. @CAM-Gerlach @ezio-melotti

@CAM-Gerlach
Copy link
Member

Seems reasonable to me—short-ish examples are reasonable for a reference, but advice like

If returning a tuple doesn’t suffice and you want name-based access to columns, you should consider setting row_factory to the highly optimized sqlite3.Row type. Row provides both index-based and case-insensitive name-based access to columns with almost no memory overhead. It will probably be better than your own custom dictionary-based approach or even a db_row based solution.

is much more appropriate in a how-to, or perhaps actually an explanation (but there isn't really enough meat for that, and a how-to is certainly closer than a reference here)

@erlend-aasland
Copy link
Contributor Author

erlend-aasland commented Aug 31, 2022

As a first step, I suggest to improve the dict-factory example by:

  • modernising the code; we can use a dict comprehension
  • using a doctest, so the expected output is visible
  • SELECTing a row with multiple columns, so the effect of the dict factory becomes clearer

erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue Aug 31, 2022
- use dict comprehension
- use doctest iso. testcode, for visualising the
  effect of the row factory
- SELECT with multiple columns, so the effect of
  the row factory becomes clearer
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 1, 2022
Co-authored-by: C.A.M. Gerlach <[email protected]>
Co-authored-by: Ezio Melotti <[email protected]>
(cherry picked from commit 91f40f3)

Co-authored-by: Erlend E. Aasland <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 1, 2022
Co-authored-by: C.A.M. Gerlach <[email protected]>
Co-authored-by: Ezio Melotti <[email protected]>
(cherry picked from commit 91f40f3)

Co-authored-by: Erlend E. Aasland <[email protected]>
erlend-aasland pushed a commit that referenced this issue Sep 1, 2022
Co-authored-by: C.A.M. Gerlach <[email protected]>
Co-authored-by: Ezio Melotti <[email protected]>
miss-islington added a commit that referenced this issue Sep 1, 2022
Co-authored-by: C.A.M. Gerlach <[email protected]>
Co-authored-by: Ezio Melotti <[email protected]>
(cherry picked from commit 91f40f3)

Co-authored-by: Erlend E. Aasland <[email protected]>
miss-islington added a commit that referenced this issue Sep 1, 2022
Co-authored-by: C.A.M. Gerlach <[email protected]>
Co-authored-by: Ezio Melotti <[email protected]>
(cherry picked from commit 91f40f3)

Co-authored-by: Erlend E. Aasland <[email protected]>
erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue Nov 15, 2022
erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue Nov 15, 2022
erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue Nov 15, 2022
erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue Nov 15, 2022
erlend-aasland added a commit that referenced this issue Nov 25, 2022
Co-authored-by: C.A.M. Gerlach <[email protected]>
Co-authored-by: Ezio Melotti <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 25, 2022
(cherry picked from commit 8749121)

Co-authored-by: Erlend E. Aasland <[email protected]>
Co-authored-by: C.A.M. Gerlach <[email protected]>
Co-authored-by: Ezio Melotti <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 25, 2022
(cherry picked from commit 8749121)

Co-authored-by: Erlend E. Aasland <[email protected]>
Co-authored-by: C.A.M. Gerlach <[email protected]>
Co-authored-by: Ezio Melotti <[email protected]>
miss-islington added a commit that referenced this issue Nov 25, 2022
(cherry picked from commit 8749121)

Co-authored-by: Erlend E. Aasland <[email protected]>
Co-authored-by: C.A.M. Gerlach <[email protected]>
Co-authored-by: Ezio Melotti <[email protected]>
miss-islington added a commit that referenced this issue Nov 25, 2022
(cherry picked from commit 8749121)

Co-authored-by: Erlend E. Aasland <[email protected]>
Co-authored-by: C.A.M. Gerlach <[email protected]>
Co-authored-by: Ezio Melotti <[email protected]>
Repository owner moved this from TODO: Docs to Done in sqlite3 issues Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir topic-sqlite3
Projects
Status: Done
Development

No branches or pull requests

2 participants