Commit graph

36 commits

Author SHA1 Message Date
924e5b4bdc Raise TransactionActive instead of returning False. 2025-03-24 22:15:58 -07:00
9385b365cd Add parameter ignore_duplicates to insert function. 2025-03-24 22:15:43 -07:00
d9a5d0811d minor linting. 2025-03-24 22:15:22 -07:00
5a06d78a65 Add call to super init. 2023-07-22 17:17:06 -07:00
eb4e381022 Check object_cache is None before pulling row id. 2023-07-22 17:16:56 -07:00
bb846a3c97 Use randomized uris for memory databases. 2023-02-25 14:14:21 -08:00
355c02cf7e Add argument transaction_mode to begin. 2022-11-12 12:38:50 -08:00
628f18e0db
Log when closing sql connections. 2022-11-07 17:55:25 -08:00
b4ec72fb53
Use execute_read for explain query plan. 2022-09-07 18:05:01 -07:00
6b26a4bd93
Add method explain which shows explain query plan. 2022-08-21 13:54:44 -07:00
1fe6de793c
Update worms to match sqlhelpers. 2022-08-13 07:24:31 -07:00
720a2bebcf
Officially prefer int for IDs.
For a while I was attracted to string IDs because of the notion
that "if you're not going to perform arithmetic, it shouldn't be
an int". But ints make way better use of the allotted bits and
I'm loving getrandbits for urandom ID generation.
2022-07-17 19:48:17 -07:00
cbef38ba7f
Add new transaction locking and cleaner atomicity in worms.
This change has really made it easier to reason about database
transactions in my projects. When you use 'with db.transaction'
you know for sure that either the db will commit or rollback at
the end and you won't leave in a dirty state. And it will lock
out all other writers so nothing gets messed up.

Previously I was conflating atomicity of each function with
committing of the entire transaction, and that was causing me
grief. I think this is closer to correct.
2022-07-17 19:48:17 -07:00
3dd270bb4a
Add method exists. 2022-07-17 19:48:16 -07:00
aeb6b89f58
Add parameter fallback to select_one_value. 2022-06-03 19:42:20 -07:00
1026d4414c
Add a calling card to @transaction for runtime determination. 2022-03-22 22:17:32 -07:00
9c9123e2d2
Update type annotation, savepoint_id is an int. 2022-03-22 22:16:42 -07:00
a76982e581
Add type annotation sqlite3.Cursor. 2022-03-22 22:16:26 -07:00
6da730e5a6
Add worms.id_type to improve behavior of int ids.
If the project uses numerical IDs, and processes user input from a web
request URL where everything is a string, it is tedious to convert
between str and int on the application side. If done improperly, it
messes up the cache because the int id and str id will be entered
separately. So we let the database handle the id type and raise errors
if necessary.
2022-03-21 19:41:59 -07:00
4b0d50c193
Add isinstance check for sqlite3.Row. 2022-03-19 20:03:50 -07:00
465f22fedb
Instead of checking get_tables, just check the COLUMN_INDEX.
This reduces the number of frivolous sql queries we make, since
the index contians all the tables anyway. The side effect is that
the function won't acknowledge tables created during the run time,
which I kind of think is a good thing since it reduces accident
surface area to the tables outlined by the programmer during init.
2022-03-19 20:03:26 -07:00
59df12a23f
Simplify worms.get_tables with select_column. 2022-03-19 19:51:25 -07:00
6867fb3011
Remove normalize_db_row, just use row_factory = Row. 2022-03-15 18:17:23 -07:00
5f5f41885e
Move get_tables into alphabetical order. 2022-03-15 13:37:28 -07:00
ee4914fa63
Add self.last_commit_id to help application know state of the world.
This allows caching layers to make better decisions about when to
reload data.
2022-03-14 15:37:46 -07:00
9b2ad4d027
Let delete, insert, update return the self.execute return value. 2022-03-14 15:35:51 -07:00
512f1591ef
Add select_one_value. 2022-03-14 15:34:41 -07:00
38f9d8046c
Add worms.raise_without_rollback. 2022-03-14 15:32:11 -07:00
ed952ffdda
Use getrandbits instead of passwordy strings for savepoint ids.
Better perf, why not.
2022-03-10 11:55:07 -08:00
d17a79c128
Store into cache using instance.id instead of requested id.
This helps ensure that the keys of the cache are the true and correct
data type and not just whatever the user provided. SQLite coerces
strings and ints.
2022-03-10 11:24:52 -08:00
9381c2c9c7
Also log commits without user-given messages. 2021-12-21 17:02:26 -08:00
691b293939
Add argument raise_for_missing. 2021-11-10 23:01:55 -08:00
71830845d4
Add note that get_objects_by_id does not raise. 2021-11-07 18:52:50 -08:00
5b6a1b4c9c
Use abstract base class to help the subclass know what to do. 2021-10-09 12:12:18 -07:00
39d6140138
Move assert_not_deleted to worms. 2021-10-02 12:45:17 -07:00
aa1e2d5756
Add worms.py. 2021-10-01 22:35:38 -07:00