sqlengine-lite 2.2.1__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 (23) hide show
  1. {sqlengine_lite-2.2.1/src/sqlengine_lite.egg-info → sqlengine_lite-2.2.2}/PKG-INFO +149 -96
  2. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/README.md +151 -98
  3. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/pyproject.toml +1 -1
  4. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/_internal/connection_manager.py +10 -7
  5. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/_internal/statements.py +24 -15
  6. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/schema.py +2 -8
  7. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/sqltable.py +7 -7
  8. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/utils/connection.py +1 -1
  9. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/utils/convert.py +12 -11
  10. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2/src/sqlengine_lite.egg-info}/PKG-INFO +149 -96
  11. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/tests/test.py +27 -11
  12. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/LICENSE +0 -0
  13. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/setup.cfg +0 -0
  14. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/__init__.py +0 -0
  15. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/_internal/__init__.py +0 -0
  16. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/_internal/repr.py +0 -0
  17. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/_internal/sqlgen.py +0 -0
  18. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/_internal/types.py +0 -0
  19. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/exceptions.py +0 -0
  20. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine/utils/__init__.py +0 -0
  21. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine_lite.egg-info/SOURCES.txt +0 -0
  22. {sqlengine_lite-2.2.1 → sqlengine_lite-2.2.2}/src/sqlengine_lite.egg-info/dependency_links.txt +0 -0
  23. {sqlengine_lite-2.2.1 → 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.1
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,38 +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
- - [Pandas-like Converter](#pandas-like-converter)
31
- - [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>
32
24
 
33
25
 
34
- # Sql-Engine
26
+ # SqlEngine
35
27
 
36
- 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)
37
32
 
38
33
 
39
34
  ## Features
40
35
 
41
- 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.
42
37
 
43
38
 
44
- 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.
45
40
 
46
41
  ```py
47
42
  from sqlengine import schema
@@ -74,66 +69,40 @@ table.select("InvoiceId", "CustomerId", "BillingAddress", "BillingCountry", "Tot
74
69
 
75
70
  ## Purpose
76
71
 
77
- 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.
78
73
 
79
- 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.
80
75
 
81
76
 
82
77
  ## Installation
83
78
 
84
- To install `sqlengine`, you can use `pip`:
79
+ To install SqlEngine, you can use `pip`:
85
80
 
86
- ```sh
81
+ ```bash
87
82
  pip install sqlengine-lite
88
83
  ```
89
84
 
90
85
  ## Env
91
86
 
92
- 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`.
93
88
 
94
89
  ```console
95
90
  SQL_ENGINE_LOG_LEVEL=INFO
96
91
  ```
97
92
 
98
- # Quick Start
99
-
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 properties of your table's columns. They are:
101
93
 
94
+ # Quick Start
102
95
 
103
- _Name of the table that will be used in queries. If omitted in inherited class declaration, then it will take the class name._
104
- ```py
105
- __tablename__ : Optional[str]
106
- ```
107
-
108
- _Column names of the table_
109
- ```py
110
- __columns__ : list[str]
111
- ```
112
-
113
- _Column types of the table_
114
- ```py
115
- __types__ : list[SqlType | str]
116
- ```
117
-
118
- _List of primary keys_
119
- ```py
120
- __primary__ : list[str]
121
- ```
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).
122
97
 
123
98
  ## Table Declaration
124
99
 
125
- 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
+
126
102
 
127
103
  ```py
128
104
  from sqlengine import SqlTableMixin, Primary
129
105
 
130
- # Helper constants for column names
131
- ID = "ID"
132
- Name = "Name"
133
- Occupation = "Occupation"
134
- Salary = "Salary"
135
-
136
-
137
106
  class Employees(SqlTableMixin):
138
107
 
139
108
  ID : Primary[int]
@@ -143,35 +112,35 @@ class Employees(SqlTableMixin):
143
112
 
144
113
  ```
145
114
 
115
+ More details at [Declaration](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/table_declaration.md#table-declaration).
116
+
146
117
  ## Instantiation
147
118
 
148
- 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.
149
120
 
150
121
  ```py
151
- # Create an instance of the table class
152
- # with provided path to create or connect to
153
- # `force_drop=True` to overwrite existing table if exists
154
-
155
122
  table = Employees("temp/data.db", force_drop=True)
156
123
  ```
157
124
 
125
+ More details at [Instantiation](https://github.com/suffermuffin/SQL-Engine/blob/main/docs/table_declaration.md#table-instantiation).
126
+
158
127
  ## Row insertion
159
128
 
160
- ```py
161
- # Insert one row
129
+ Insert one row in a `*args` style.
162
130
 
131
+ ```py
163
132
  table.insert(1, "John Doe", "Software Engineer", 75000.0)
164
133
  ```
165
134
 
166
- ```py
167
- # Use kwargs mapping to insert/upsert one row
135
+ Use **kwargs mapping** to insert/upsert one row
168
136
 
137
+ ```py
169
138
  table.insert(2, salary=80000.0, name="Jane Smith", occupation="Data Scientist")
170
139
  ```
171
140
 
172
- ```py
173
- # Bulk insert multiple rows
141
+ Bulk insert multiple rows.
174
142
 
143
+ ```py
175
144
  employees_data = [
176
145
  (3, "Alice Johnson", "Product Manager", 90000.0),
177
146
  (4, "Bob Brown", "Project Manager", 78000.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,36 +297,68 @@ 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
 
344
+ Save query result to csv.
345
+
323
346
  ```py
324
- # Save query result to csv
325
347
  to_csv(table.select.where.gt(Salary, 70_000), "temp/query.csv")
326
348
  ```
327
349
 
350
+ Stream big tables or query results to csv.
351
+
328
352
  ```py
329
- # Stream to csv
330
353
  with table.transaction():
331
354
  to_csv(table, "temp/query.csv", stream_batch_size=1000)
332
355
  ```
333
356
 
334
357
  ## Pandas-like Converter
335
358
 
359
+ Convert tables or query results to pandas **DataFrame** in one shot.
360
+
336
361
  ```py
337
- # via one shot
338
362
  import pandas as pd
339
363
  from sqlengine.utils import to_dicts
340
364
 
@@ -342,8 +366,9 @@ df = pd.DataFrame(to_dicts(table))
342
366
  df.set_index("ID", inplace=True)
343
367
  ```
344
368
 
369
+ Or stream them via generator.
370
+
345
371
  ```py
346
- # via generator
347
372
  import pandas as pd
348
373
  from sqlengine.utils import to_dicts_stream
349
374
 
@@ -356,6 +381,34 @@ with table.transaction():
356
381
  df.set_index("ID", inplace=True)
357
382
  ```
358
383
 
359
- # Full Documentation
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
360
413
 
361
- 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).