Skip to content

Commit

Permalink
Update to v1.1.5
Browse files Browse the repository at this point in the history
- New Methods:
1. get_top(total)
2. select_top(total)

- ReadMe Update
- Package Update
  • Loading branch information
CodeConfidant committed Aug 13, 2021
1 parent bcdd45c commit 0dc072c
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 3 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@
Select and return a list of dictionaries with each dictionary representing a row in the db_table attribute table.
</td>
</tr>
<tr>
<td>
<code>get_top(total)</code>
</td>
<td>
Select and return a list of dictionaries representing rows in the db_table attribute table limited to the number designated in the 'total' argument.
</td>
</tr>
<tr>
<td>
<code>rename_table(tablename)</code>
Expand Down Expand Up @@ -280,6 +288,14 @@
Select and output to terminal the rows from the db_table attribute table.
</td>
</tr>
<tr>
<td>
<code>select_top(total)</code>
</td>
<td>
Select and output to terminal the rows from the db_table attribute table limited to the number designated in the 'total' argument.
</td>
</tr>
<tr>
<td>
<code>select_column(*args)</code>
Expand Down
6 changes: 5 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ get_row(key, value): Select and return a dictionary representin

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

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.

rename_table(tablename): Rename db_table attribute table.

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

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

select_table(): Select and output to terminal the rows from the db_table attribute table.
select_table(): Select and output to terminal the rows from the db_table attribute table.

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.

select_column(*args): Select and output to terminal the values from keys within the db_table attribute table.
Each arg in *args arguments must be strings containing key names within the table.
Expand Down
58 changes: 58 additions & 0 deletions connectwrap/connectwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,50 @@ def get_table(self):

return table

# Select and return a list of dictionaries representing rows in the db_table attribute table limited to the number designated in the 'total' argument.
def get_top(self, total):
if (self.connection_status != True):
raise db.DatabaseNotOpenError("Database is not open! The connection status attribute is not set to True!")

if (db.table_exists(self, self.db_table) == False):
raise db.TableNotFoundError("The db_table attribute table doesn't exist within the database!")

if (type(total) is not int):
raise TypeError("The total argument isn't an int!")

table = list([])
keys = list(db.get_keys(self))
query = str("SELECT * FROM {0} LIMIT {1}").format(self.db_table, total)

for row in db.execute(self, query):
row_dict = dict.fromkeys(keys)
row_factor = list([])
i = int(0)

for column in row:
column = str(column).strip("(,')")

if (column.isdigit() == True):
column = int(column)
elif (utils.isfloat(column) == True):
column = float(column)
elif (utils.ishex(column) == True):
column = bytes.fromhex(column)
elif (column == "None"):
column = None
else:
column = str(column)

row_factor.append(column)

for key in row_dict:
row_dict[key] = row_factor[i]
i += 1

table.append(row_dict)

return table

# Rename db_table attribute table.
def rename_table(self, table):
if (self.connection_status != True):
Expand Down Expand Up @@ -428,6 +472,20 @@ def select_table(self):

for row in db.get_table(self):
print(self.db_table, "Row:", row)

# Select and output to terminal the rows from the db_table attribute table limited to the number designated in the 'total' argument.
def select_top(self, total):
if (self.connection_status != True):
raise db.DatabaseNotOpenError("Database is not open! The connection status attribute is not set to True!")

if (db.table_exists(self, self.db_table) == False):
raise db.TableNotFoundError("The db_table attribute table doesn't exist within the database!")

if (type(total) is not int):
raise TypeError("The total argument isn't an int!")

for row in db.get_top(self, total):
print(self.db_table, "Row:", row)

# Select and output to terminal the values from keys within the db_table attribute table.
# Each arg in *args arguments must be strings containing key names within the table.
Expand Down
Binary file removed dist/connectwrap-1.1.4.tar.gz
Binary file not shown.
Binary file added dist/connectwrap-1.1.5.tar.gz
Binary file not shown.
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env python3
# Setup python package - python setup.py sdist

# Tar Wrap the Package: python setup.py sdist
# Upload to PYPI: twine upload dist/*

from setuptools import setup, find_packages

setup(
name='connectwrap',
version='1.1.4',
version='1.1.5',
packages=find_packages(),
license='MIT',
description='A Python package for SQLite database management & object relational mapping.',
Expand Down
3 changes: 3 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
# Select row values in Crew table and output them to terminal.
demo_database.select_table()

# Select top 3 row values in Crew table and output them to terminal.
demo_database.select_top(3)

# Select column values by key first_name and output them to terminal.
demo_database.select_column("first_name")

Expand Down

0 comments on commit 0dc072c

Please sign in to comment.