sqlitables 0.1.0__py3-none-any.whl
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.
sqlitables/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from sqlitables import classes, connection
|
sqlitables/classes.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import sqlite3
|
|
2
|
+
|
|
3
|
+
class Column:
|
|
4
|
+
def __init__(self, name: str, datatype: str):
|
|
5
|
+
self.name = name
|
|
6
|
+
self.datatype = datatype
|
|
7
|
+
def statement(self):
|
|
8
|
+
statement = f'"{self.name}" {self.datatype}'
|
|
9
|
+
return statement
|
|
10
|
+
|
|
11
|
+
class Table:
|
|
12
|
+
def __init__(self, name: str, columns: list[Column]):
|
|
13
|
+
self.name = name
|
|
14
|
+
self.columns = columns
|
|
15
|
+
def exists(self, cursor: sqlite3.Cursor):
|
|
16
|
+
sql = f'SELECT name FROM sqlite_master WHERE type="table" AND name="{self.name}";'
|
|
17
|
+
find = cursor.execute(sql)
|
|
18
|
+
exists = True if find.fetchone() else False
|
|
19
|
+
return exists
|
|
20
|
+
def create(self, cursor: sqlite3.Cursor):
|
|
21
|
+
sql = f'CREATE TABLE "{self.name}"( '
|
|
22
|
+
for index, column in enumerate(self.columns):
|
|
23
|
+
sql += column.statement()
|
|
24
|
+
if index != len(self.columns) - 1: sql += ', '
|
|
25
|
+
sql += ');'
|
|
26
|
+
cursor.execute(sql)
|
|
27
|
+
def insert(self, values: list[tuple], connection: sqlite3.Connection):
|
|
28
|
+
sql = f'INSERT INTO "{self.name}" VALUES '
|
|
29
|
+
for index, value in enumerate(values): # enumerate list
|
|
30
|
+
sql += '('
|
|
31
|
+
for tupleindex, field in enumerate(value): # enumerate tuple
|
|
32
|
+
if type(field) == str:
|
|
33
|
+
sql += f'"{field}"'
|
|
34
|
+
else:
|
|
35
|
+
sql += str(field)
|
|
36
|
+
if tupleindex != len(value) - 1: sql += ', '
|
|
37
|
+
sql += ')'
|
|
38
|
+
if index != len(values) - 1: sql += ', '
|
|
39
|
+
sql += ';'
|
|
40
|
+
connection.cursor().execute(sql).close()
|
|
41
|
+
connection.commit()
|
|
42
|
+
def select(self, select: list[Column] | str, where: str | None, cursor: sqlite3.Cursor):
|
|
43
|
+
sql = 'SELECT '
|
|
44
|
+
if type(select) == str:
|
|
45
|
+
if select == "*":
|
|
46
|
+
sql += f'* FROM {self.name}'
|
|
47
|
+
else:
|
|
48
|
+
raise ValueError('The select parameter can only include a list of Column objects or "*".')
|
|
49
|
+
else:
|
|
50
|
+
for index, col in enumerate(select):
|
|
51
|
+
sql += f'"{col.name}"' # type: ignore ;; reads col a possible string when it is not.
|
|
52
|
+
if index != len(select) - 1: sql += ', '
|
|
53
|
+
sql += f' FROM {self.name}'
|
|
54
|
+
if where:
|
|
55
|
+
sql += f' WHERE {where}'
|
|
56
|
+
sql += ";"
|
|
57
|
+
selection = cursor.execute(sql)
|
|
58
|
+
return selection.fetchall()
|
sqlitables/connection.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sqlitables
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Create and maintain SQLite databases more efficiently using object-oriented concepts
|
|
5
|
+
Project-URL: Repository, https://github.com/MICHI64N/sqlitables
|
|
6
|
+
Project-URL: Changelog, https://github.com/MICHI64N/sqlitables/blob/main/CHANGELOG.md
|
|
7
|
+
Author-email: Samantha Bales <samanthabales2006@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: classes,database,object-oriented,oop,sql,sqlite
|
|
11
|
+
Classifier: Development Status :: 1 - Planning
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Database
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# SQLiTables
|
|
21
|
+
*Create and maintain SQLite databases more efficiently using object-oriented concepts*
|
|
22
|
+
## Resources
|
|
23
|
+
* SQLiTables is built on top of sqlite3, a standard Python module. [Its documentation](https://docs.python.org/3/library/sqlite3.html) may be helpful for using this library.
|
|
24
|
+
## Features
|
|
25
|
+
*This is an early-stage project with limited features.*
|
|
26
|
+
* Connect to the database ([usage](https://github.com/MICHI64N/sqlitables/blob/main/docs/usage.md#connect-to-the-database)).
|
|
27
|
+
* Create a table in the database ([usage](https://github.com/MICHI64N/sqlitables/blob/main/docs/usage.md#create-a-table-in-the-database)).
|
|
28
|
+
* Insert values into a table ([usage](https://github.com/MICHI64N/sqlitables/blob/main/docs/usage.md#insert-values-into-a-table)).
|
|
29
|
+
* Select values from a table ([usage](https://github.com/MICHI64N/sqlitables/blob/main/docs/usage.md#select-values-from-a-table)).
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
sqlitables/__init__.py,sha256=G3EMZK21hxvn3RkIMrv1HrQ53MpHwuq8GCZTF90mH6M,42
|
|
2
|
+
sqlitables/classes.py,sha256=1A4rHEUCYdESTgY6HOwqeJRhqyh5MaXN0KMEFngnwdU,2323
|
|
3
|
+
sqlitables/connection.py,sha256=RbiQaQrHskG46mtZdfLYNhHI_3UPWYcInvbd-P_Dq8g,146
|
|
4
|
+
sqlitables-0.1.0.dist-info/METADATA,sha256=zYuv-EKzdhIZTojURqmT-ak9uWAlbEnl4r2ykreb8Us,1703
|
|
5
|
+
sqlitables-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
6
|
+
sqlitables-0.1.0.dist-info/licenses/LICENSE,sha256=MgG-JhWsi6Z2TV6l-TtuW9LnEHo0LJIWtm15BSwkssA,1070
|
|
7
|
+
sqlitables-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Samantha Bales
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|