sqlengine-lite 2.2.0__tar.gz → 2.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {sqlengine_lite-2.2.0/src/sqlengine_lite.egg-info → sqlengine_lite-2.2.2}/PKG-INFO +181 -98
  2. {sqlengine_lite-2.2.0 → sqlengine_lite-2.2.2}/README.md +183 -100
  3. {sqlengine_lite-2.2.0 → sqlengine_lite-2.2.2}/pyproject.toml +8 -2
  4. sqlengine_lite-2.2.2/src/sqlengine/__init__.py +11 -0
  5. sqlengine_lite-2.2.2/src/sqlengine/_internal/__init__.py +4 -0
  6. sqlengine_lite-2.2.0/src/sqlengine/core/connection.py → sqlengine_lite-2.2.2/src/sqlengine/_internal/connection_manager.py +25 -11
  7. {sqlengine_lite-2.2.0/src/sqlengine/core → sqlengine_lite-2.2.2/src/sqlengine/_internal}/statements.py +53 -22
  8. {sqlengine_lite-2.2.0/src/sqlengine/core → sqlengine_lite-2.2.2/src/sqlengine/_internal}/types.py +9 -8
  9. sqlengine_lite-2.2.2/src/sqlengine/exceptions.py +20 -0
  10. {sqlengine_lite-2.2.0 → sqlengine_lite-2.2.2}/src/sqlengine/schema.py +3 -9
  11. {sqlengine_lite-2.2.0 → sqlengine_lite-2.2.2}/src/sqlengine/sqltable.py +100 -68
  12. sqlengine_lite-2.2.2/src/sqlengine/utils/__init__.py +4 -0
  13. {sqlengine_lite-2.2.0 → sqlengine_lite-2.2.2}/src/sqlengine/utils/connection.py +12 -9
  14. sqlengine_lite-2.2.2/src/sqlengine/utils/convert.py +130 -0
  15. {sqlengine_lite-2.2.0 → sqlengine_lite-2.2.2/src/sqlengine_lite.egg-info}/PKG-INFO +181 -98
  16. {sqlengine_lite-2.2.0 → sqlengine_lite-2.2.2}/src/sqlengine_lite.egg-info/SOURCES.txt +7 -6
  17. {sqlengine_lite-2.2.0 → sqlengine_lite-2.2.2}/tests/test.py +190 -39
  18. sqlengine_lite-2.2.0/src/sqlengine/__init__.py +0 -7
  19. sqlengine_lite-2.2.0/src/sqlengine/core/__init__.py +0 -4
  20. sqlengine_lite-2.2.0/src/sqlengine/utils/__init__.py +0 -4
  21. sqlengine_lite-2.2.0/src/sqlengine/utils/convert.py +0 -24
  22. {sqlengine_lite-2.2.0 → sqlengine_lite-2.2.2}/LICENSE +0 -0
  23. {sqlengine_lite-2.2.0 → sqlengine_lite-2.2.2}/setup.cfg +0 -0
  24. {sqlengine_lite-2.2.0/src/sqlengine/core → sqlengine_lite-2.2.2/src/sqlengine/_internal}/repr.py +0 -0
  25. {sqlengine_lite-2.2.0/src/sqlengine/core → sqlengine_lite-2.2.2/src/sqlengine/_internal}/sqlgen.py +0 -0
  26. {sqlengine_lite-2.2.0 → sqlengine_lite-2.2.2}/src/sqlengine_lite.egg-info/dependency_links.txt +0 -0
  27. {sqlengine_lite-2.2.0 → sqlengine_lite-2.2.2}/src/sqlengine_lite.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlengine-lite
3
- Version: 2.2.0
3
+ Version: 2.2.2
4
4
  Summary: Cute sqlite3 wrapper for sql tables
5
5
  Project-URL: Homepage, https://github.com/suffermuffin/SQL-Engine
6
6
  Project-URL: Repository, https://github.com/suffermuffin/SQL-Engine.git
@@ -10,37 +10,33 @@ Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
11
  Dynamic: license-file
12
12
 
13
- - [Sql-Engine](#sql-engine)
14
- - [Features](#features)
15
- - [Purpose](#purpose)
16
- - [Installation](#installation)
17
- - [Env](#env)
18
- - [Quick Start](#quick-start)
19
- - [Table Declaration](#table-declaration)
20
- - [Instantiation](#instantiation)
21
- - [Row insertion](#row-insertion)
22
- - [Jupyter view](#jupyter-view)
23
- - [Select Query](#select-query)
24
- - [Update Query](#update-query)
25
- - [Delete Query](#delete-query)
26
- - [Transaction](#transaction)
27
- - [Get Item](#get-item)
28
- - [Custom Types](#custom-types)
29
- - [Csv Converter](#csv-converter)
30
- - [Full Documentation](#full-documentation)
13
+ <p align="center">
14
+ <a href="https://github.com/suffermuffin/SQL-Engine/actions/workflows/test.yml?query=event%3Apush">
15
+ <img src="https://github.com/suffermuffin/SQL-Engine/actions/workflows/test.yml/badge.svg?event=push&branch=main" alt="Tests">
16
+ </a>
17
+ <a href="https://github.com/suffermuffin/SQL-Engine/actions?query=workflow%3APublish">
18
+ <img src="https://github.com/suffermuffin/SQL-Engine/actions/workflows/publish.yml/badge.svg" alt="Publishing">
19
+ </a>
20
+ <a href="https://pypi.org/project/sqlengine-lite/">
21
+ <img alt="PyPI" src="https://img.shields.io/pypi/v/sqlengine-lite?logoSize=amd&labelColor=black&color=royalblue">
22
+ </a>
23
+ </p>
31
24
 
32
25
 
33
- # Sql-Engine
26
+ # SqlEngine
34
27
 
35
- My Sql-Engine is a cute little wrapper for `sqlite3` table manipulations without any third party dependencies.
28
+ My SqlEngine is a cute little wrapper for `sqlite3` table manipulations without any third party dependencies.
29
+
30
+
31
+ [**Home Page**](https://github.com/suffermuffin/SQL-Engine) | [**Installation**](#installation) | [**Quick Start**](#quick-start) | [**Documentation**](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/index.md)
36
32
 
37
33
 
38
34
  ## Features
39
35
 
40
- Abstracts SQL queries into tiny little methods like, `insert`, `insert_many`, `upsert`, and not so little and tiny query builders a-la `select`, `delete`, `update`, etc. Sql-Engine also provides bulk insertion and transaction methods, like `insert_many` and `select.fetchmany_iterator`. Methods can be executed in transaction mode thanks to `transaction` context manager.
36
+ SqlEngine abstracts SQL queries into tiny little methods like `insert`, `insert_many`, `upsert`, and not so tiny (but still cute and little) query builders like `select`, `delete` and `update`. SqlEngine also provides bulk insertion with `insert_many` and transaction operations like `select.fetchmany_iterator`. Methods can be executed either in transaction mode (thanks to `transaction` context manager) or right on the spot.
41
37
 
42
38
 
43
- Sql-Engine implements Jupyter integration and dynamic schema building. You can easily instantiate existing database table and view it in cute little html representation.
39
+ SqlEngine implements Jupyter integration and dynamic schema building. You can easily instantiate existing database table and view it in a cute little html representation.
44
40
 
45
41
  ```py
46
42
  from sqlengine import schema
@@ -73,106 +69,79 @@ table.select("InvoiceId", "CustomerId", "BillingAddress", "BillingCountry", "Tot
73
69
 
74
70
  ## Purpose
75
71
 
76
- It's a tiny little modern ORM-like that lets you prototype your databases locally with great flexibility. Also, it can be used in production apps to store and retrieve data, because all select, update, delete queries are parametrized. But it does not restrict you from using your own queries which might not be paramerized with methods like `select.custom()` and `where.custom()`.
72
+ It's a tiny little modern ORM-like that lets you prototype your databases locally with great flexibility. Also, it can be used in production apps to store and retrieve data, because all select, update, delete queries are parametrized. But it does not restrict you from using your own queries which might not be parameterized with methods like `select.custom()` and `where.custom()`. Flexibility is a go to for this library.
77
73
 
78
- And last (but not least) is data inspection. If you need to quickly inspect existing .db file but don't want to install yet another heavy ORM with a lot of unused dependencies, you might look into Sql-Engine, as it uses only native python modules.
74
+ And last (but not least) is data inspection. If you need to quickly inspect existing .db file but don't want to install yet another heavy ORM with a lot of unused dependencies and features, you might look into SqlEngine, as it uses only native python modules, implements dynamic schema builder and has a good synergy with Jupyter Notebook.
79
75
 
80
76
 
81
77
  ## Installation
82
78
 
83
- To install `sqlengine`, you can use `pip`:
79
+ To install SqlEngine, you can use `pip`:
84
80
 
85
- ```sh
81
+ ```bash
86
82
  pip install sqlengine-lite
87
83
  ```
88
84
 
89
85
  ## Env
90
86
 
91
- You may set environment variable for logging. By default it's `WARNING`.
87
+ You can set environment variable for logging. By default it's `WARNING`.
92
88
 
93
89
  ```console
94
90
  SQL_ENGINE_LOG_LEVEL=INFO
95
91
  ```
96
92
 
97
- # Quick Start
98
-
99
- All you have to do to create your own cute little table is to [inherit](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/table_declaration.md#class-declaration) `SqlTableMixin` class or to create your own [schema](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/table_declaration.md#schema-declaration) and declare desired properties of your table's columns. They are:
100
-
101
-
102
- _Name of the table that will be used in queries. If omitted in inherited class declaration, then it will take the class name._
103
- ```py
104
- __tablename__ : Optional[str]
105
- ```
106
93
 
107
- _Column names of the table_
108
- ```py
109
- __columns__ : list[str]
110
- ```
94
+ # Quick Start
111
95
 
112
- _Column types of the table_
113
- ```py
114
- __types__ : list[SqlType | str]
115
- ```
116
-
117
- _List of primary keys_
118
- ```py
119
- __primary__ : list[str]
120
- ```
96
+ Here lays everything you need to know to start working with SqlEngine. For detailed usage, API reference, and advanced examples, see the [full documentation](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/index.md).
121
97
 
122
98
  ## Table Declaration
123
99
 
124
- More details at [Declaration](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/table_declaration.md#table-declaration).
100
+ All you have to do to create your own cute little table is to [inherit](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/table_declaration.md#class-declaration) `SqlTableMixin` class or to create your own [schema](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/table_declaration.md#schema-declaration) and declare desired types of your table's columns.
101
+
125
102
 
126
103
  ```py
127
104
  from sqlengine import SqlTableMixin, Primary
128
105
 
129
- # Helper constants for column names
130
- ID = "ID"
131
- Name = "Name"
132
- Occupation = "Occupation"
133
- Salary = "Salary"
134
-
135
-
136
106
  class Employees(SqlTableMixin):
137
107
 
138
108
  ID : Primary[int]
139
- Name : str
109
+ Name : str | None
140
110
  Occupation : str
141
111
  Salary : float
142
112
 
143
- # You may overwrite your insert methods for type consistency
144
- def insert(self, id : int, name : str, occupation : str, salary : float) -> None:
145
- return super().insert(id, name, occupation, salary)
146
-
147
- def upsert(self, id : int, name : str, occupation : str, salary : float) -> None:
148
- return super().upsert(id, name, occupation, salary)
149
113
  ```
150
114
 
115
+ More details at [Declaration](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/table_declaration.md#table-declaration).
116
+
151
117
  ## Instantiation
152
118
 
153
- More details at [Instantiation](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/table_declaration.md#table-instantiation).
119
+ Create an instance of the table class with provided path to create or connect to. `force_drop=True` to overwrite existing table if it exists.
154
120
 
155
121
  ```py
156
- # Create an instance of the table class
157
- # with provided path to create or connect to
158
- # `force_drop=True` to overwrite existing table if exists
159
-
160
122
  table = Employees("temp/data.db", force_drop=True)
161
123
  ```
162
124
 
125
+ More details at [Instantiation](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/table_declaration.md#table-instantiation).
126
+
163
127
  ## Row insertion
164
128
 
165
- ```py
166
- # Insert one row
129
+ Insert one row in a `*args` style.
167
130
 
131
+ ```py
168
132
  table.insert(1, "John Doe", "Software Engineer", 75000.0)
169
133
  ```
170
134
 
135
+ Use **kwargs mapping** to insert/upsert one row
136
+
171
137
  ```py
172
- # Bulk insert multiple rows
138
+ table.insert(2, salary=80000.0, name="Jane Smith", occupation="Data Scientist")
139
+ ```
140
+
141
+ Bulk insert multiple rows.
173
142
 
143
+ ```py
174
144
  employees_data = [
175
- (2, "Jane Smith", "Data Scientist", 80000.0),
176
145
  (3, "Alice Johnson", "Product Manager", 90000.0),
177
146
  (4, "Bob Brown", "Project Manager", 78000.0),
178
147
  (5, "Charlie Davis", "UI/UX Designer", 65000.0),
@@ -187,17 +156,17 @@ table.insert_many(employees_data)
187
156
  ```
188
157
 
189
158
 
190
- ```py
191
- # Upsert one row
159
+ Upsert one row.
192
160
 
161
+ ```py
193
162
  table.upsert(1, "Jane Doe", "Data Scientist", 80000.0)
194
163
  ```
195
164
 
196
165
  ## Jupyter view
197
166
 
198
- ```py
199
- # Inspect tables in Jupyter Notebook
167
+ Inspect table in Jupyter Notebook.
200
168
 
169
+ ```py
201
170
  table
202
171
  ```
203
172
 
@@ -205,11 +174,18 @@ table
205
174
 
206
175
  ## Select Query
207
176
 
208
- More details at [Statements](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/statements.md).
177
+ Helper constants for column names.
209
178
 
210
179
  ```py
211
- # Query select and fetch
180
+ ID = "ID"
181
+ Name = "Name"
182
+ Occupation = "Occupation"
183
+ Salary = "Salary"
184
+ ```
212
185
 
186
+ Query **select** and **fetch** in one go.
187
+
188
+ ```py
213
189
  table.select.where.between(ID, 3, 5).then.fetchall()
214
190
 
215
191
  # ->
@@ -218,9 +194,24 @@ table.select.where.between(ID, 3, 5).then.fetchall()
218
194
  # (5, 'Charlie Davis', 'UI/UX Designer', 65000.0)]
219
195
  ```
220
196
 
197
+ **Iterate** over select statements.
198
+
221
199
  ```py
222
- # Inspect query select in Jupyter
200
+ with table.transaction():
201
+ for id, occupation in table.select(ID, Occupation).where.gt(Salary, 70_000):
202
+ print(id, occupation)
203
+ ```
223
204
 
205
+ ```console
206
+ 1 Data Scientist
207
+ 3 Product Manager
208
+ 4 Project Manager
209
+ 6 DevOps Engineer
210
+ ```
211
+
212
+ Inspect select query in Jupyter.
213
+
214
+ ```py
224
215
  table.select(Name, Salary).where.lt(Salary, 70_000)
225
216
  ```
226
217
 
@@ -239,33 +230,32 @@ table.update(Salary, 50_000).where.eq(Name, "Eve Taylor").then.execute()
239
230
  table.delete.where.eq(ID, 5).then.execute()
240
231
  ```
241
232
 
233
+ More details at [Statements](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/statements.md).
234
+
242
235
  ## Transaction
243
236
 
244
- More details at [Transaction](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/transactions.md).
237
+ Operate within a transaction
245
238
 
246
239
  ```py
247
- # Operate within a transaction
248
240
 
249
241
  with table.transaction():
250
242
  for row in employees_data:
251
243
  table.upsert(*row)
252
244
  ```
253
245
 
246
+ More details at [Transaction](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/transactions.md).
247
+
254
248
  ## Get Item
255
249
 
256
- More details at [Syntax Sugar](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/syntax_sugar.md).
250
+ Fetch row by primary key.
257
251
 
258
252
  ```py
259
- # Fetch row by primary key
260
-
261
- table[9]
262
-
263
- # -> (9, 'Grace Hall', 'Marketing Manager', 68000.0)
253
+ table[9] # -> (9, 'Grace Hall', 'Marketing Manager', 68000.0)
264
254
  ```
265
255
 
266
- ```py
267
- # Fetch slice by integer primary key
256
+ Fetch slice by integer primary key.
268
257
 
258
+ ```py
269
259
  table[4:10:2]
270
260
 
271
261
  # ->
@@ -274,9 +264,11 @@ table[4:10:2]
274
264
  # (8, 'Frank White', 'Quality Assurance', 53000.0)]
275
265
  ```
276
266
 
267
+ More details at [Syntax Sugar](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/syntax_sugar.md).
268
+
277
269
  ## Custom Types
278
270
 
279
- More details at [Custom Types](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/custom_types.md).
271
+ Declare your own non-native SQL type to be compatible with sqlite3.
280
272
 
281
273
  ```py
282
274
  from datetime import datetime
@@ -305,27 +297,118 @@ class ReservationIndex(SqlTableMixin):
305
297
 
306
298
  table = ReservationIndex("temp/data.db")
307
299
 
308
- table.insert(1, "loft_1", DateTime.now(), None)
300
+ table.insert(
301
+ user_id=1,
302
+ room_id="loft_1",
303
+ time_at=DateTime.now()
304
+ )
309
305
  table
310
306
  ```
311
307
 
312
308
  <table style="border-collapse: collapse; font-size: 14px;"><caption style="font-size: 18px; font-weight: bold;">ReservationIndex</caption><thead><tr><td style="border: 1px solid #555; text-align: center;">user_id</td><td style="border: 1px solid #555; text-align: center;">room_id</td><td style="border: 1px solid #555; text-align: center;">time_at</td><td style="border: 1px solid #555; text-align: center;">user_name</td></tr></thead><tbody><tr><td style="border: 1px solid #000; text-align: center;">1</td><td style="border: 1px solid #000; text-align: center;">loft_1</td><td style="border: 1px solid #000; text-align: center;">2026-05-29 21:29:00</td><td style="border: 1px solid #000; text-align: center;">None</td></tr></tbody></table>
313
309
 
310
+ More details at [Custom Types](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/custom_types.md).
311
+
312
+ ## Pure SQL
313
+
314
+ Use SQL queries directly.
315
+
316
+ ```py
317
+ with table.transaction(autocommit=False):
318
+ table.conn.execute("DELETE FROM ReservationIndex WHERE user_id = 1;")
319
+ table.commit()
320
+ ```
321
+
322
+ Same as:
323
+
324
+ ```py
325
+ table.conn.execute("DELETE FROM ReservationIndex WHERE user_id = 1;")
326
+ ```
327
+
328
+ ```py
329
+ table
330
+ ```
331
+
332
+ <table style="border-collapse: collapse; font-size: 14px;"><caption style="font-size: 18px; font-weight: bold;">ReservationIndex</caption><thead><tr><td style="border: 1px solid #555; text-align: center;">user_id</td><td style="border: 1px solid #555; text-align: center;">room_id</td><td style="border: 1px solid #555; text-align: center;">time_at</td><td style="border: 1px solid #555; text-align: center;">user_name</td></tr></thead><tbody></tbody></table>
333
+
314
334
  ## Csv Converter
315
335
 
336
+ Save table to csv.
337
+
316
338
  ```py
317
- # Save table to csv
318
339
  from sqlengine.utils import to_csv
319
340
 
320
341
  to_csv(table, "temp/table.csv")
321
342
  ```
322
343
 
323
- ```py
324
- # Save query result to csv
344
+ Save query result to csv.
325
345
 
346
+ ```py
326
347
  to_csv(table.select.where.gt(Salary, 70_000), "temp/query.csv")
327
348
  ```
328
349
 
329
- # Full Documentation
350
+ Stream big tables or query results to csv.
351
+
352
+ ```py
353
+ with table.transaction():
354
+ to_csv(table, "temp/query.csv", stream_batch_size=1000)
355
+ ```
356
+
357
+ ## Pandas-like Converter
358
+
359
+ Convert tables or query results to pandas **DataFrame** in one shot.
360
+
361
+ ```py
362
+ import pandas as pd
363
+ from sqlengine.utils import to_dicts
364
+
365
+ df = pd.DataFrame(to_dicts(table))
366
+ df.set_index("ID", inplace=True)
367
+ ```
368
+
369
+ Or stream them via generator.
370
+
371
+ ```py
372
+ import pandas as pd
373
+ from sqlengine.utils import to_dicts_stream
374
+
375
+ df = pd.DataFrame(columns=table.columns)
376
+
377
+ with table.transaction():
378
+ for batch in to_dicts_stream(table, batch_size=1000):
379
+ df = pd.concat([df, pd.DataFrame(batch)], axis=0)
380
+
381
+ df.set_index("ID", inplace=True)
382
+ ```
383
+
384
+ # Contributions
385
+
386
+ Your impact is welcome. Install module from source if you want to contribute:
387
+
388
+ ```bash
389
+ git clone https://github.com/suffermuffin/SQL-Engine.git
390
+ cd SQL-Engine
391
+ ```
392
+
393
+ Use `uv` to sync dependencies and checkout to your new branch:
394
+
395
+ ```bash
396
+ uv sync
397
+ git checkout -b "<your_feature_or_fix_name>"
398
+ ```
399
+
400
+ Don't forget to run tests after the implementation:
401
+
402
+ ```bash
403
+ uv run python -m unittest discover -s tests
404
+ ```
405
+
406
+ And update api documentation with your docstrings:
407
+
408
+ ```bash
409
+ pydoc-markdown
410
+ ```
411
+
412
+ # License
330
413
 
331
- For detailed usage, API reference, and advanced examples, see the [full documentation](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/index.md).
414
+ This project is licensed under the terms of the [MIT license](https://github.com/suffermuffin/SQL-Engine/blob/main/LICENSE).