A database that is very easy to set up and use
Project description
Easy DB
This simple and easy-to-use library comes with a few important functions to start storing data easier! It comes loaded with functions to read, write, and delete data. This doesn't require too much setup, but it still requires some user input and data to setup tables. Tables are made in JSON (JavaScript Object Notation), so they are very easy to read.
Dependencies
- Python 3.8 or above
Docs
Table(filename, tablename) | Class
This is the table class, which holds all the information for one table.
Parameters
- filename [type: string]: file the table will be or is stored in
- tablename [type: string]: the name of your table
Attributes
- deleted [type: boolean, default: False]: if the table is deleted (using a method in the class), the value of the variable changes to True, methods cannot be carried out without the variable being True
- set [type: boolean, default: False]: value changes to True if table is set, methods cannot be carried out without the variable being True
- filename [type: string]: file the table will be or is stored in
- tablename [type: string]: the name of your table
Example
example = Table('example_file.json', 'Example Table')
Methods
setup_table(args, already_set)
Use
Sets up the table and sets the set attribute to True so that other methods in the table can be carried out.
Parameters
- already_set [type: bool, default: False]: if the table is already setup, set the value to True and ignore args
- args [type: list, default: None]: should be ignored if table is already setup, if table is not setup, this is a list all the columns of the table
Example
If table is not set
example.setup_table(args=['name', 'state', 'country'])
If table is set
example.setup_table(already_set=True)
apdata(primary_key, args)
Use
Can add and update rows of data using the primary key passed in.
Parameters
- primary_key [type: string]: distinct identifier of each row in the table, if the primary key passed as a parameter doesn't exist in the table already a new row will be added with the primary key as the identifier, if the primary key already exists in the table all data corresponding to the primary key will be updated with new data
- args [type: list]: the data corresponding to the primary, should be placed in the order of the table's columns
Raises
- ValueError - if number of arguments does not correspond to the number of columns in the table
Example
example.apdata('Person1', ['John', 'Texas', 'US'])
# adds data to a table with the primary key as "Person1"
get_keys(*key)
Use
Returns data from specific columns in the form of a dictionary.
Parameters
- key [type: string]: column names
Example
data = example.get_keys('name', 'state')
print(data)
# returns data from only the "name" and "state" column
get(primary_key)
Use
Returns all the data that corresponds to a primary key in the dictionary.
Parameters
- primary_key [type: string]: the primary key that corresponds to the row of data you want to get
Example
data = example.get('Person1')
print(data)
delete(primary_key)
Use
Deletes a row from the table, using the primary key to identify the row.
Parameters
- primary_key [type: string]: the primary key that corresponds to the row of data you want to delete
Example
example.delete('Person1')
req_args()
Use
Returns all the column names of the table.
Parameters
None
Example
arguments = example.req_args()
print(arguments)
check_if_table_setup()
Use
Checks if the table is setup and sets the set attribute to True.
Parameters
None
Raises
- ValueError: if the table is not setup
Example
example.check_if_table_setup()
deltable()
Use
Deletes the table.
Parameters
None
Example
example.deltable()
check_if_table_is_deleted()
Use
Checks if the table is deleted and sets the deleted attribute to True.
Parameters
None
Raises
- ValueError: if the table has been deleted
Example
example.check_if_table_is_deleted()
number_of_args()
Use
Returns the number of columns in the table.
Parameters
None
Example
number = example.number_of_args()
print(number)
number_of_rows()
Use
Returns the number of rows in the table.
Parameters
None
Example
number = example.number_of_rows()
print(number)
To-Do
- Make CLI using EasyDB functions and classes
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file EasyDatabase-2.1.tar.gz
.
File metadata
- Download URL: EasyDatabase-2.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43c83e8b2a60fec18a020ee2bcde2d69a17051fc578d997da9de0518565ee3b9 |
|
MD5 | 511a1bda82788ac0d270a37a2a1ea01b |
|
BLAKE2b-256 | 3e4eab95fd2b5992c60b9651895b50ead8932cdb610279fc08988377a11ebbad |
File details
Details for the file EasyDatabase-2.1-py3-none-any.whl
.
File metadata
- Download URL: EasyDatabase-2.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b19eda8931c267789d8d2921dce5e58df594730c093c02359e9b088407f4f54 |
|
MD5 | 0a95e71d5d64afee2cfb05d5d85b8c97 |
|
BLAKE2b-256 | 7cf4a478a6f9240d0c4e87deccdc2dbd2849f704514a15c4ee41e4643a8b6c8d |