sqlthon 0.1.4__tar.gz → 0.2.0__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.
sqlthon-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.4
2
+ Name: sqlthon
3
+ Version: 0.2.0
4
+ Summary: A simple package for SQLite3 operations
5
+ Author-email: SAUMS <supportsqlthon@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/SAUMS-1391/sqlthon
8
+ Project-URL: Repository, https://github.com/SAUMS-1391/sqlthon
9
+ Project-URL: Documentation, https://sqlthon.readthedocs.io/
10
+ Project-URL: Issues, https://github.com/SAUMS-1391/sqlthon/issues
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+
17
+ # Sqlthon
18
+
19
+ A powerful, Pythonic layer for SQLite3 — built for developers who don't know SQL.
20
+
21
+ ## Why Sqlthon?
22
+
23
+ SQLite is powerful, but using it requires knowing SQL. Sqlthon lets you work with SQLite databases using **pure Python objects and methods** — no SQL queries needed. Just define your tables and fields, and Sqlthon handles the rest.
24
+
25
+ **Sqlthon is:**
26
+ - ✅ A powerful layer for working with SQLite3 in pure Python
27
+ - ✅ Built for developers who don't know SQL
28
+ - ✅ Suitable for real projects and production use
29
+
30
+ **Sqlthon is NOT:**
31
+ - ❌ A replacement for the built-in `sqlite3` module
32
+ - ❌ A toy package for tiny scripts
33
+ - ❌ Feature-complete yet — it's under active development
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ pip install sqlthon
@@ -0,0 +1,22 @@
1
+ # Sqlthon
2
+
3
+ A powerful, Pythonic layer for SQLite3 — built for developers who don't know SQL.
4
+
5
+ ## Why Sqlthon?
6
+
7
+ SQLite is powerful, but using it requires knowing SQL. Sqlthon lets you work with SQLite databases using **pure Python objects and methods** — no SQL queries needed. Just define your tables and fields, and Sqlthon handles the rest.
8
+
9
+ **Sqlthon is:**
10
+ - ✅ A powerful layer for working with SQLite3 in pure Python
11
+ - ✅ Built for developers who don't know SQL
12
+ - ✅ Suitable for real projects and production use
13
+
14
+ **Sqlthon is NOT:**
15
+ - ❌ A replacement for the built-in `sqlite3` module
16
+ - ❌ A toy package for tiny scripts
17
+ - ❌ Feature-complete yet — it's under active development
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install sqlthon
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sqlthon"
7
- version = '0.1.4'
7
+ version = '0.2.0'
8
8
  description = "A simple package for SQLite3 operations"
9
9
  readme = "README.md"
10
- requires-python = ">=3.8"
10
+ requires-python = ">=3.10"
11
11
  license = {text = "MIT"}
12
12
  authors = [
13
- {name = "SAUMS", email = "mohamnown@gmail.com"}
13
+ {name = "SAUMS", email = "supportsqlthon@gmail.com"}
14
14
  ]
15
15
  classifiers = [
16
16
  "Programming Language :: Python :: 3",
@@ -0,0 +1,21 @@
1
+ """
2
+ A Simple Package For SQLite3 Operations.
3
+
4
+ ||||| |||| || |||||| || || |||||| || ||
5
+ || || || || || || || || || ||| ||
6
+ |||| || || || || |||||| || || ||||||
7
+ || |||| || || || || || || || |||
8
+ ||||| || |||||| || || || || || ||||||
9
+
10
+ Github: https://Github.com/saums-1391/sqlthon
11
+ Channel: https://ble.ir/Sqlthon
12
+ """
13
+
14
+ from .core import Connect, Field
15
+
16
+ __all__ = ['Field', 'Connect']
17
+
18
+ __version__ = '0.2.0'
19
+ __author__ = "SAUMS"
20
+ __email__ = "supportsqlthon@gmail.com"
21
+ __description__ = "A Simple Package For SQLite3 Operations."
@@ -1,7 +1,10 @@
1
+ from .errors import (SqlthonError, YouHackerError, TableError, TableNotFoundError, TableAlreadyExistsError, ColumnError, ColumnNotFoundError, RecordError, UniqueConstraintError, NotNullConstraintError, DataTypeError, ForeignKeyError, CheckConstraintError, PrimaryKeyError, QueryError, SyntaxError_, NoSuchFunctionError, WrongNumberOfArgumentsError, DatabaseError, DatabaseLockedError, DatabaseReadOnlyError, DatabaseCorruptError, DatabaseFullError, DatabaseBusyError, IndexError_, IndexNotFoundError, IndexAlreadyExistsError, ViewError, ViewNotFoundError, ViewAlreadyExistsError, TransactionError, TransactionAlreadyActiveError, TransactionNotActiveError, BackupError, BackupPathError, BackupPermissionError, CsvError, CsvFileNotFoundError, CsvFormatError, PandasError, PandasNotInstalledError, ValidationError, InvalidColumnCountError, InvalidValueError)
1
2
  class Field:
2
3
  __slots__ = ("name",)
3
4
  def __init__(self, name):
4
5
  _analysis_code(name)
6
+ if "." in name:
7
+ name = name.replace(".", "\".\"")
5
8
  self.name = name
6
9
 
7
10
  def __gt__(self, value): return _Expression(self, ">", value)
@@ -165,9 +168,12 @@ class Connect:
165
168
  def add_column(self, table_name: str, column_name: str, column_type: str, limits: list | str=[]) -> None:
166
169
  _analysis_code(table_name)
167
170
  _analysis_code(column_name)
168
- _analysis_code(column_type)
171
+ if column_type.count(" ") > 2 or "--" in column_type or "/*" in column_type:
172
+ raise YouHackerError(f"you hacker for {column_type!r}.") from None
169
173
  if limits:
170
- _analysis_code(limits)
174
+ for limit in limits:
175
+ if "--" in limit:
176
+ raise YouHackerError(f"you hacker for {limit!r}.") from None
171
177
  limits = " ".join(limits)
172
178
  else:
173
179
  limits = ""
@@ -215,7 +221,7 @@ class Connect:
215
221
  del _
216
222
  if bundle:
217
223
  _analysis_code(bundle)
218
- query += f" GROUP BY {", ".join(bundle)}"
224
+ query += f' GROUP BY {", ".join(bundle)}'
219
225
  if filter_bundle:
220
226
  __: tuple = _compile(filter_bundle)
221
227
  query += f" HAVING {__[0]}"
@@ -293,17 +299,25 @@ class Connect:
293
299
  colue = dict(zip(self.get_columns(table_name), info_record)) # columns value
294
300
  for i in conflict:
295
301
  del colue[i]
296
- for key, value in colue.items():
297
- query += f'"{key}"=?, '
298
- param += (value,)
299
- query = query[:-2]
302
+ if colue:
303
+ for key, value in colue.items():
304
+ query += f'"{key}"=?, '
305
+ param += (value,)
306
+ query = query[:-2]
307
+ else:
308
+ query = query.replace(" DO UPDATE SET", " DO NOTHING")
300
309
  self._changes.append((query, param))
301
310
 
302
311
  # ____________| INDEX |_________
303
312
  def add_index(self, table_name: str, column_name: str, unique: bool=False) -> None:
304
313
  _analysis_code(table_name)
305
314
  _analysis_code(column_name)
306
- self._changes.append((f"CREATE INDEX{" UNIQUE" if unique else ""} {table_name}_{column_name} ON {table_name} ({column_name})",))
315
+
316
+ self._changes.append((
317
+ f"CREATE {'UNIQUE ' if unique else ''}INDEX "
318
+ f"{table_name}_{column_name} ON "
319
+ f"{table_name} ({column_name})",
320
+ ))
307
321
 
308
322
  def delete_index(self, table_name: str, column_name: str) -> None:
309
323
  _analysis_code(table_name)
@@ -312,7 +326,8 @@ class Connect:
312
326
 
313
327
  # ____________| VIEW |_________
314
328
  def add_view(self, view_name: str, query: str) -> None:
315
- raise YouHackerError("add_view is disabled for security reasons.")
329
+ _analysis_code(view_name)
330
+ self._changes.append((f"CREATE VIEW {view_name} AS {query}",))
316
331
 
317
332
  def delete_view(self, view_name: str) -> None:
318
333
  _analysis_code(view_name)
@@ -323,22 +338,19 @@ class Connect:
323
338
  return view_name in [i[0] for i in self._cur.execute("SELECT name FROM sqlite_master WHERE type='view'").fetchall()]
324
339
 
325
340
  # ____________| BACKUP |_________
326
- def backup_database(self, backup_path: str | None=None) -> None:
327
- from shutil import copy2
328
- from os.path import abspath, dirname, join
329
- self._con.commit()
330
- allowed_dir = dirname(abspath(self._path))
331
- if backup_path:
332
- if not abspath(backup_path).startswith(allowed_dir):
333
- raise YouHackerError(f"you hacker for {backup_path!r}.")
334
- copy2(self._path, backup_path)
335
- else:
336
- copy2(self._path, join(allowed_dir, "backup.db"))
341
+ def backup_database(self, backup_path: str) -> None:
342
+ self.save_to_database()
343
+ import sqlite3
344
+ with sqlite3.connect(backup_path) as target:
345
+ self._con.backup(target)
337
346
 
338
347
  # ____________| PANDAS |_________
339
348
  def to_dataframe(self, table_name: str) -> "pd.DataFrame":
340
349
  _analysis_code(table_name)
341
- import pandas as pd
350
+ try:
351
+ import pandas as pd
352
+ except:
353
+ raise PandasNotInstalledError("you have not installed the pandas package yet.")
342
354
  columns = self.get_columns(table_name)
343
355
  result = self._cur.execute(f"SELECT * FROM {table_name}").fetchall()
344
356
  return pd.DataFrame(result, columns=columns)
@@ -396,7 +408,12 @@ class Connect:
396
408
 
397
409
  # ____________| BASIC |_________
398
410
  def run_query(self, code: str, parameters: tuple=()) -> list:
399
- raise YouHackerError("run_query is disabled for security reasons.")
411
+ try:
412
+ self._cur.execute(code, parameters)
413
+ except Exception as e:
414
+ _handler_error(e)
415
+ self._con.commit()
416
+ return self._cur.fetchall()
400
417
 
401
418
  def optimize(self) -> None:
402
419
  self.save_to_database()
@@ -419,58 +436,20 @@ class Connect:
419
436
  def __enter__(self) -> "Connect":
420
437
  return self
421
438
 
422
- def __exit__(self, exc_type, exc_value, exc_tb) -> None:
423
- self.save_to_database()
424
- self.close()
439
+ def __exit__(self, exc_type, exc_value, traceback) -> bool:
440
+ try:
441
+ if exc_type is None:
442
+ self.save_to_database()
443
+ else:
444
+ self._changes.clear()
445
+ self._con.rollback()
446
+ finally:
447
+ self.close()
448
+
449
+ return False
425
450
 
426
451
 
427
- # ____________| ERRORS |_________
428
- class SqlthonError(Exception):__module__ = None
429
- class YouHackerError(SqlthonError, PermissionError):__module__ = None
430
- class TableError(SqlthonError):__module__ = None
431
- class TableNotFoundError(TableError):__module__ = None
432
- class TableAlreadyExistsError(TableError):__module__ = None
433
- class ColumnError(SqlthonError):__module__ = None
434
- class ColumnNotFoundError(ColumnError):__module__ = None
435
- class RecordError(SqlthonError):__module__ = None
436
- class UniqueConstraintError(RecordError):__module__ = None
437
- class NotNullConstraintError(RecordError):__module__ = None
438
- class DataTypeError(RecordError):__module__ = None
439
- class ForeignKeyError(RecordError):__module__ = None
440
- class CheckConstraintError(RecordError):__module__ = None
441
- class PrimaryKeyError(RecordError):__module__ = None
442
- class QueryError(SqlthonError):__module__ = None
443
- class SyntaxError(QueryError):__module__ = None
444
- class NoSuchFunctionError(QueryError):__module__ = None
445
- class WrongNumberOfArgumentsError(QueryError):__module__ = None
446
- class DatabaseError(SqlthonError):__module__ = None
447
- class DatabaseLockedError(DatabaseError):__module__ = None
448
- class DatabaseReadOnlyError(DatabaseError):__module__ = None
449
- class DatabaseCorruptError(DatabaseError):__module__ = None
450
- class DatabaseFullError(DatabaseError):__module__ = None
451
- class DatabaseBusyError(DatabaseError):__module__ = None
452
- class IndexError(SqlthonError):__module__ = None
453
- class IndexNotFoundError(IndexError):__module__ = None
454
- class IndexAlreadyExistsError(IndexError):__module__ = None
455
- class ViewError(SqlthonError):__module__ = None
456
- class ViewNotFoundError(ViewError):__module__ = None
457
- class ViewAlreadyExistsError(ViewError):__module__ = None
458
- class TransactionError(SqlthonError):__module__ = None
459
- class TransactionAlreadyActiveError(TransactionError):__module__ = None
460
- class TransactionNotActiveError(TransactionError):__module__ = None
461
- class BackupError(SqlthonError):__module__ = None
462
- class BackupPathError(BackupError):__module__ = None
463
- class BackupPermissionError(BackupError):__module__ = None
464
- class CsvError(SqlthonError):__module__ = None
465
- class CsvFileNotFoundError(CsvError):__module__ = None
466
- class CsvFormatError(CsvError):__module__ = None
467
- class PandasError(SqlthonError):__module__ = None
468
- class PandasNotInstalledError(PandasError):__module__ = None
469
- class ValidationError(SqlthonError):__module__ = None
470
- class InvalidColumnCountError(ValidationError):__module__ = None
471
- class InvalidValueError(ValidationError):__module__ = None
472
-
473
-
452
+ # ____________| ERROR |_________
474
453
  def _handler_error(e: Exception):
475
454
  msg = str(e).lower()
476
455
 
@@ -508,7 +487,7 @@ def _handler_error(e: Exception):
508
487
  raise WrongNumberOfArgumentsError(msg) from None
509
488
 
510
489
  elif "syntax error" in msg:
511
- raise SyntaxError(f"invalid {msg.split()[-1].replace('"', "'")}") from None
490
+ raise SyntaxError_(f"invalid {msg.split()[-1].replace('"', "'")}") from None
512
491
 
513
492
  elif "database is locked" in msg:
514
493
  raise DatabaseLockedError(msg) from None
@@ -0,0 +1,44 @@
1
+ class SqlthonError(Exception):__module__ = None
2
+ class YouHackerError(SqlthonError, PermissionError):__module__ = None
3
+ class TableError(SqlthonError):__module__ = None
4
+ class TableNotFoundError(TableError):__module__ = None
5
+ class TableAlreadyExistsError(TableError):__module__ = None
6
+ class ColumnError(SqlthonError):__module__ = None
7
+ class ColumnNotFoundError(ColumnError):__module__ = None
8
+ class RecordError(SqlthonError):__module__ = None
9
+ class UniqueConstraintError(RecordError):__module__ = None
10
+ class NotNullConstraintError(RecordError):__module__ = None
11
+ class DataTypeError(RecordError):__module__ = None
12
+ class ForeignKeyError(RecordError):__module__ = None
13
+ class CheckConstraintError(RecordError):__module__ = None
14
+ class PrimaryKeyError(RecordError):__module__ = None
15
+ class QueryError(SqlthonError):__module__ = None
16
+ class SyntaxError_(QueryError):__module__ = None
17
+ class NoSuchFunctionError(QueryError):__module__ = None
18
+ class WrongNumberOfArgumentsError(QueryError):__module__ = None
19
+ class DatabaseError(SqlthonError):__module__ = None
20
+ class DatabaseLockedError(DatabaseError):__module__ = None
21
+ class DatabaseReadOnlyError(DatabaseError):__module__ = None
22
+ class DatabaseCorruptError(DatabaseError):__module__ = None
23
+ class DatabaseFullError(DatabaseError):__module__ = None
24
+ class DatabaseBusyError(DatabaseError):__module__ = None
25
+ class IndexError_(SqlthonError):__module__ = None
26
+ class IndexNotFoundError(IndexError_):__module__ = None
27
+ class IndexAlreadyExistsError(IndexError_):__module__ = None
28
+ class ViewError(SqlthonError):__module__ = None
29
+ class ViewNotFoundError(ViewError):__module__ = None
30
+ class ViewAlreadyExistsError(ViewError):__module__ = None
31
+ class TransactionError(SqlthonError):__module__ = None
32
+ class TransactionAlreadyActiveError(TransactionError):__module__ = None
33
+ class TransactionNotActiveError(TransactionError):__module__ = None
34
+ class BackupError(SqlthonError):__module__ = None
35
+ class BackupPathError(BackupError):__module__ = None
36
+ class BackupPermissionError(BackupError):__module__ = None
37
+ class CsvError(SqlthonError):__module__ = None
38
+ class CsvFileNotFoundError(CsvError):__module__ = None
39
+ class CsvFormatError(CsvError):__module__ = None
40
+ class PandasError(SqlthonError):__module__ = None
41
+ class PandasNotInstalledError(PandasError):__module__ = None
42
+ class ValidationError(SqlthonError):__module__ = None
43
+ class InvalidColumnCountError(ValidationError):__module__ = None
44
+ class InvalidValueError(ValidationError):__module__ = None
@@ -1,3 +1,4 @@
1
+ from .core import _Aggregate
1
2
  STR = "TEXT"
2
3
  INT = "INTEGER"
3
4
  FLOAT = "REAL"
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.4
2
+ Name: sqlthon
3
+ Version: 0.2.0
4
+ Summary: A simple package for SQLite3 operations
5
+ Author-email: SAUMS <supportsqlthon@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/SAUMS-1391/sqlthon
8
+ Project-URL: Repository, https://github.com/SAUMS-1391/sqlthon
9
+ Project-URL: Documentation, https://sqlthon.readthedocs.io/
10
+ Project-URL: Issues, https://github.com/SAUMS-1391/sqlthon/issues
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+
17
+ # Sqlthon
18
+
19
+ A powerful, Pythonic layer for SQLite3 — built for developers who don't know SQL.
20
+
21
+ ## Why Sqlthon?
22
+
23
+ SQLite is powerful, but using it requires knowing SQL. Sqlthon lets you work with SQLite databases using **pure Python objects and methods** — no SQL queries needed. Just define your tables and fields, and Sqlthon handles the rest.
24
+
25
+ **Sqlthon is:**
26
+ - ✅ A powerful layer for working with SQLite3 in pure Python
27
+ - ✅ Built for developers who don't know SQL
28
+ - ✅ Suitable for real projects and production use
29
+
30
+ **Sqlthon is NOT:**
31
+ - ❌ A replacement for the built-in `sqlite3` module
32
+ - ❌ A toy package for tiny scripts
33
+ - ❌ Feature-complete yet — it's under active development
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ pip install sqlthon
@@ -2,6 +2,7 @@ README.md
2
2
  pyproject.toml
3
3
  src/sqlthon/__init__.py
4
4
  src/sqlthon/core.py
5
+ src/sqlthon/errors.py
5
6
  src/sqlthon/keywords.py
6
7
  src/sqlthon.egg-info/PKG-INFO
7
8
  src/sqlthon.egg-info/SOURCES.txt
sqlthon-0.1.4/PKG-INFO DELETED
@@ -1,24 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: sqlthon
3
- Version: 0.1.4
4
- Summary: A simple package for SQLite3 operations
5
- Author-email: SAUMS <mohamnown@gmail.com>
6
- License: MIT
7
- Project-URL: Homepage, https://github.com/SAUMS-1391/sqlthon
8
- Project-URL: Repository, https://github.com/SAUMS-1391/sqlthon
9
- Project-URL: Documentation, https://sqlthon.readthedocs.io/
10
- Project-URL: Issues, https://github.com/SAUMS-1391/sqlthon/issues
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: OS Independent
14
- Requires-Python: >=3.8
15
- Description-Content-Type: text/markdown
16
-
17
- # Sqlthon
18
-
19
- A simple package for SQLite3 operations.
20
-
21
- ## Installation
22
-
23
- ```bash
24
- pip install sqlthon
sqlthon-0.1.4/README.md DELETED
@@ -1,8 +0,0 @@
1
- # Sqlthon
2
-
3
- A simple package for SQLite3 operations.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- pip install sqlthon
@@ -1,21 +0,0 @@
1
- """
2
- A Simple Package For SQLite3 Operations.
3
-
4
- ||||| |||| || |||||| || || |||||| || ||
5
- || || || || || || || || || ||| ||
6
- |||| || || || || |||||| || || ||||||
7
- || |||| || || || || || || || |||
8
- ||||| || |||||| || || || |||||| || ||
9
-
10
- Github: https://Github.com/saums-1391/sqlthon
11
- Channel: https://ble.ir/saums_channel
12
-
13
- """
14
-
15
- from .core import *
16
-
17
- __all__ = ['Field', 'Connect', 'SqlthonError', 'YouHackerError', 'TableError', 'TableNotFoundError', 'TableAlreadyExistsError', 'ColumnError', 'ColumnNotFoundError', 'RecordError', 'UniqueConstraintError', 'NotNullConstraintError', 'DataTypeError', 'ForeignKeyError', 'CheckConstraintError', 'PrimaryKeyError', 'QueryError', 'SyntaxError', 'NoSuchFunctionError', 'WrongNumberOfArgumentsError', 'DatabaseError', 'DatabaseLockedError', 'DatabaseReadOnlyError', 'DatabaseCorruptError', 'DatabaseFullError', 'DatabaseBusyError', 'IndexError', 'IndexNotFoundError', 'IndexAlreadyExistsError', 'ViewError', 'ViewNotFoundError', 'ViewAlreadyExistsError', 'TransactionError', 'TransactionAlreadyActiveError', 'TransactionNotActiveError', 'BackupError', 'BackupPathError', 'BackupPermissionError', 'CsvError', 'CsvFileNotFoundError', 'CsvFormatError', 'PandasError', 'PandasNotInstalledError', 'ValidationError', 'InvalidColumnCountError', 'InvalidValueError']
18
- __version__ = '0.1.4'
19
- __author__ = "SAUMS"
20
- __email__ = "saums1391@gmail.com"
21
- __description__ = "Operate With SQLite3 Buy Simple"
@@ -1,24 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: sqlthon
3
- Version: 0.1.4
4
- Summary: A simple package for SQLite3 operations
5
- Author-email: SAUMS <mohamnown@gmail.com>
6
- License: MIT
7
- Project-URL: Homepage, https://github.com/SAUMS-1391/sqlthon
8
- Project-URL: Repository, https://github.com/SAUMS-1391/sqlthon
9
- Project-URL: Documentation, https://sqlthon.readthedocs.io/
10
- Project-URL: Issues, https://github.com/SAUMS-1391/sqlthon/issues
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: OS Independent
14
- Requires-Python: >=3.8
15
- Description-Content-Type: text/markdown
16
-
17
- # Sqlthon
18
-
19
- A simple package for SQLite3 operations.
20
-
21
- ## Installation
22
-
23
- ```bash
24
- pip install sqlthon
File without changes