Skip to content

Commit 0dc072c

Browse files
committed
Update to v1.1.5
- New Methods: 1. get_top(total) 2. select_top(total) - ReadMe Update - Package Update
1 parent bcdd45c commit 0dc072c

7 files changed

Lines changed: 86 additions & 3 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@
218218
Select and return a list of dictionaries with each dictionary representing a row in the db_table attribute table.
219219
</td>
220220
</tr>
221+
<tr>
222+
<td>
223+
<code>get_top(total)</code>
224+
</td>
225+
<td>
226+
Select and return a list of dictionaries representing rows in the db_table attribute table limited to the number designated in the 'total' argument.
227+
</td>
228+
</tr>
221229
<tr>
222230
<td>
223231
<code>rename_table(tablename)</code>
@@ -280,6 +288,14 @@
280288
Select and output to terminal the rows from the db_table attribute table.
281289
</td>
282290
</tr>
291+
<tr>
292+
<td>
293+
<code>select_top(total)</code>
294+
</td>
295+
<td>
296+
Select and output to terminal the rows from the db_table attribute table limited to the number designated in the 'total' argument.
297+
</td>
298+
</tr>
283299
<tr>
284300
<td>
285301
<code>select_column(*args)</code>

README.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ get_row(key, value): Select and return a dictionary representin
7373

7474
get_table(): Select and return a list of dictionaries with each dictionary representing a row in the db_table attribute table.
7575

76+
get_top(total): Select and return a list of dictionaries representing rows in the db_table attribute table limited to the number designated in the 'total' argument.
77+
7678
rename_table(tablename): Rename db_table attribute table.
7779

7880
drop_table(table): Drop/delete table in the file database.
@@ -91,7 +93,9 @@ create_column(column, datatype): Create a new column within the db_table at
9193

9294
select_tablenames(): Select and output to terminal the table names within a database.
9395

94-
select_table(): Select and output to terminal the rows from the db_table attribute table.
96+
select_table(): Select and output to terminal the rows from the db_table attribute table.
97+
98+
select_top(total): Select and output to terminal the rows from the db_table attribute table limited to the number designated in the 'total' argument.
9599

96100
select_column(*args): Select and output to terminal the values from keys within the db_table attribute table.
97101
Each arg in *args arguments must be strings containing key names within the table.

connectwrap/connectwrap.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,50 @@ def get_table(self):
262262

263263
return table
264264

265+
# Select and return a list of dictionaries representing rows in the db_table attribute table limited to the number designated in the 'total' argument.
266+
def get_top(self, total):
267+
if (self.connection_status != True):
268+
raise db.DatabaseNotOpenError("Database is not open! The connection status attribute is not set to True!")
269+
270+
if (db.table_exists(self, self.db_table) == False):
271+
raise db.TableNotFoundError("The db_table attribute table doesn't exist within the database!")
272+
273+
if (type(total) is not int):
274+
raise TypeError("The total argument isn't an int!")
275+
276+
table = list([])
277+
keys = list(db.get_keys(self))
278+
query = str("SELECT * FROM {0} LIMIT {1}").format(self.db_table, total)
279+
280+
for row in db.execute(self, query):
281+
row_dict = dict.fromkeys(keys)
282+
row_factor = list([])
283+
i = int(0)
284+
285+
for column in row:
286+
column = str(column).strip("(,')")
287+
288+
if (column.isdigit() == True):
289+
column = int(column)
290+
elif (utils.isfloat(column) == True):
291+
column = float(column)
292+
elif (utils.ishex(column) == True):
293+
column = bytes.fromhex(column)
294+
elif (column == "None"):
295+
column = None
296+
else:
297+
column = str(column)
298+
299+
row_factor.append(column)
300+
301+
for key in row_dict:
302+
row_dict[key] = row_factor[i]
303+
i += 1
304+
305+
table.append(row_dict)
306+
307+
return table
308+
265309
# Rename db_table attribute table.
266310
def rename_table(self, table):
267311
if (self.connection_status != True):
@@ -428,6 +472,20 @@ def select_table(self):
428472

429473
for row in db.get_table(self):
430474
print(self.db_table, "Row:", row)
475+
476+
# Select and output to terminal the rows from the db_table attribute table limited to the number designated in the 'total' argument.
477+
def select_top(self, total):
478+
if (self.connection_status != True):
479+
raise db.DatabaseNotOpenError("Database is not open! The connection status attribute is not set to True!")
480+
481+
if (db.table_exists(self, self.db_table) == False):
482+
raise db.TableNotFoundError("The db_table attribute table doesn't exist within the database!")
483+
484+
if (type(total) is not int):
485+
raise TypeError("The total argument isn't an int!")
486+
487+
for row in db.get_top(self, total):
488+
print(self.db_table, "Row:", row)
431489

432490
# Select and output to terminal the values from keys within the db_table attribute table.
433491
# Each arg in *args arguments must be strings containing key names within the table.

dist/connectwrap-1.1.4.tar.gz

-7.73 KB
Binary file not shown.

dist/connectwrap-1.1.5.tar.gz

8.03 KB
Binary file not shown.

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/usr/bin/env python3
2-
# Setup python package - python setup.py sdist
2+
3+
# Tar Wrap the Package: python setup.py sdist
4+
# Upload to PYPI: twine upload dist/*
35

46
from setuptools import setup, find_packages
57

68
setup(
79
name='connectwrap',
8-
version='1.1.4',
10+
version='1.1.5',
911
packages=find_packages(),
1012
license='MIT',
1113
description='A Python package for SQLite database management & object relational mapping.',

test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
# Select row values in Crew table and output them to terminal.
4141
demo_database.select_table()
4242

43+
# Select top 3 row values in Crew table and output them to terminal.
44+
demo_database.select_top(3)
45+
4346
# Select column values by key first_name and output them to terminal.
4447
demo_database.select_column("first_name")
4548

0 commit comments

Comments
 (0)