Database management system based on python and JSON.
Project description
Documentation
Table of content
Preface
Tutorial
- 1.1 Installation
- 1.2 Creating database
- 1.3 Creating a New Table
- 1.4 Populating a table with rows
- 1.5 Querying a Table
- 1.6 Updates
- 1.7 Deletion
Preface
1. What is sayuDB
sayuDB is an database management system based on python and JSON. Developed at Clee Ltd. This project actually for personal purpose only but for some reason I publish it. It supports a large part of the SQL standard feature
Tutorial
1. Getting Started
1.1 Installation
Before you can use sayuDB you need to install it, of course. Just clone this repository and place it to your project folder.
> pip3 install sayuDB
for help menu:
> python3 sayuDB --h
1.2 Creating database
The first test to see whether you can access the database server is to try to create a database.
To create a new database, in this example named myDB
, you use the following funtion:
import sayuDB
# Creating database
sayuDB.create_database('myDB')
You can also create databases with other names. sayuDB allows you to create any number of databases at a given site. Database names must have an alphabetic first character, can not contain space and are limited to 63 bytes in length.
If you do not want to use your database anymore you can remove it. For example, you can destroy it using the following function:
import sayuDB
sayuDB.drop_database('myDB')
You can import export using:
# Exporting database (must use file name)
sayuDB.export_database('<name_of_database>', path_='<path>/filename.ezdb')
# Importing database
sayuDB.import_database(path_='/<path>/filename.ezdb')
1.3 Creating a New Table
You can create a new table by specifying the table name, along with all column names and their types:
you must define the database first with:
import sayuDB
db = sayuDB.sayuDB(database='myDB')
then
db.create_table('people', [
['name','str'],
['age','int'],
['city','str']
])
sayuDB currenly support data types str
,int
,float
,dict
If you want to show the table, using this following function:
db.show_table(name='people')
it will returned as printed table:
name column datas
------ -------- -------
Finally, it should be mentioned that if you don't need a table any longer or want to recreate it differently you can remove it using the following function:
db.drop_table(name='people')
1.4 Populating a Table With Rows
The insert_row
function is used to populate a table with rows:
db.insert_row(table='people', col='name,age,city', contents=['Arsybai', 23, 'Solo, Indonesia'])
You can also use col as list. EX ['name','age','city']
1.5 Querying a Table
To retrieve data from a table, the table is queried. An select_row
funtion is used to do this. The funtion is divided into a select list (the part that lists the columns to be returned), a table list (the part that lists the tables from which to retrieve the data), and an optional qualification (the part that specifies any restrictions). For example, to retrieve all the rows of table people
, type:
data = db.select_row(table='people', col='*')
print(data)
Here *
is a shorthand for “all columns”. So the same result would be had with:
db.select_row(table='people', col='name,age,city')
The output should be:
name age city
------- ----- ------------------
Arsybai 23 Solo, Indonesia
Ataro 25 Bekasi, Indonesia
Moepoi 21 Jakarta, Indonesia
If you want the output is json, use as_json=True
:
data = db.select_row(table='people', col='*', as_json=True)
print(data)
A query can be “qualified” by adding a where
clause that specifies which rows are wanted:
data = db.select_row(table='people', col='*', where='age=23')
print(data)
you can also use contain
for specific column that contain some value:
data = db.select_row(table='people', col='*', where='age contain 23')
print(data)
Result:
name age city
------- ----- ---------------
Arsybai 23 Solo, Indonesia
You can request that the results of a query be returned in sorted order:
data = db.select_row(table='people', col='*', order_by='age|asc')
print(data)
The order should be asc
or desc
Result:
name age city
------- ----- ------------------
Moepoi 21 Jakarta, Indonesia
Arsybai 23 Solo, Indonesia
Ataro 25 Bekasi, Indonesia
Updates
You can update existing rows using the update_row
.
as example I want to set Ataro
age to 26
:
db.update_row(table='people', set_='age=26', where='name=Ataro')
Look at the new state of the data:
name age city
------- ----- ------------------
Arsybai 23 Solo, Indonesia
Ataro 26 Bekasi, Indonesia
Moepoi 21 Jakarta, Indonesia
Deletion
Rows can be removed from a table using the delete_row
:
db.delete_row(table='people', where='name=Ataro')
Look at the new state of the data:
name age city
------- ----- ------------------
Arsybai 23 Solo, Indonesia
Moepoi 21 Jakarta, Indonesia
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 sayuDB-0.0.3.tar.gz
.
File metadata
- Download URL: sayuDB-0.0.3.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 083904512bdebb863748744dac0600996beefc8b6c3c31ca971cb8b6c6b1d805 |
|
MD5 | 57c42a55d2c90ae02009c382de54bfd4 |
|
BLAKE2b-256 | 5f30107de030438f9d96730e4f50b36813c16e775a2e00bb232b1efe1e99b144 |
File details
Details for the file sayuDB-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: sayuDB-0.0.3-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c9d1d2c76551e69490520f5fb0c61a6a74b0da0b8d8c2147ce3542a282e1b2e |
|
MD5 | 8dabc7d952ebbd8ace5b2edf4e4a5f78 |
|
BLAKE2b-256 | 20247c37f342bcaeea20cd5ccfad9690cf63ca97ab33fb8bc46238591e6f60f1 |