Package: sayuDB
PrefaceWhat is sayuDBsayuDB 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 featureTutorialTable of contentsInstallationCreate or remove userGrant privileges to userCreate and drop databaseImport and export databaseActivate or deactivate serverUsing the sayuDBCreate tableDrop tableShow tableInsertSelectWhereUpdateDeleteAlter tableClear tableInstallation>pip3installsayuDBand if you want to show help menu just> python3 -m sayuDB --hCreate or remove userTo create a user you can command by>python3-msayuDBcreateuser<username><password>and if you want to remove user you can command by>python3-msayuDBremoveuser<username>Note that creating or removing user only can be user when you have root/local access.
the user is use for remote database. if you want to user this database locally, you didn't need this.And for show user, you can command by>python3-msayuDBshowusersGrant privileges to userOfcourse you need to grant user to some database first before use it remotely.
Grant it by command>python3-msayuDBgrantuser<username><database_name>Create and drop databaseTo create a database, just command by>python3createdatabase<database_name>And to drop/delete it, just command by>python3-msayuDBdropdatabase<database_name>Anyway, you can also show databases by>python3-msayuDBshowdatabasesImport and export databaseTo import a database, just command by>python3-msayuDBimportdatabase<path_to_ezdb_file>And for export it, just command by>python3-msayuDBexportdatabase<database_name><output_path>Activate or deactivate serverIf you want the database remotely online. just activate server by>python3-msayuDBactivateserver<port>Note: I recomended use 8787 as portthen acces it within your server IP.
if you didn't see something, try make the server public by>python3-msayuDBsetuppublicserver<server_name><port>Theserver_nameis your server IP or a domain that already set A record to your server IP.
And theportmust be same when you activate it.If you want to deactivate it, just command by>python3-msayuDBdeactivateserverUsing the sayuDBTo user sayu db in python, just define it first byimportsayuDB# Importing the sayuDBdb=sayuDB.sayuDB("testdb")# call the classThe parameters areparameterstatusdescriptiondatabaserequiredthe database nameusernameoptionalthe username for you sayuDB account if you access it remotelypasswordoptionalofc the passwordhostoptionalthe host of your database hosted inas_jsonoptionalthis is the boolean if you want to return the database as json or just printed table.Create tableTo create a table use this following functiondb.create_table("<table_name>",col=[["number","int"],["name","str"],["age","int"],["address","str"]])The parameters areparameterstatusdescriptionnamerequiredthe name of table you want to createcolrequireda lists that contain list wich contain the column name and datatypes[ ["<column_name>","<datatypes>"] ]Note: supported datatypesstr,float,int,dictDrop tableYou can drop table by use this dollowing functiondb.drop_table("<table_name>")The parameters areparameterstatusdescriptionnamerequiredthe name of the table you want to drop/deleteShow tableyou can show the table by use this following funtion.db.show_table("<table_name>")it will returnednumbernameageaddress
----------------------------InsertTo insert some row to the table, you can use this following functiondb.insert_row(table="<table_name>",col="number,name,age,address",contents=[1,"Arsybai",23,"Solo, Indonesia"])The parameters areparameterstatusdescriptiontablerequiredThe name of table you want to insert a rowcolrequiredthe column that you want to insert. separate by comma or you can use listcontentsrequiredthe contents/value for each columnand now if you show the table it will look like thisnumbernameageaddress
-----------------------------------1Arsybai23Solo,Indonesiaand you can also insert it with some function. as example I want to insert moepoi as number 2. but I want the number automatically increased.db.insert_row(table="<table_name>",col="number,name,age,address",contents=["increase()","Moepoi",20,"Jakarta, Indonesia"])So, I use '`increase()' function for it. then the table will look like thisnumbernameageaddress
--------------------------------------1Arsybai23Solo,Indonesia2Moepoi20Jakarta,IndonesiaTable of functionsnamedescriptiontoday()Generate today datetime (only work in str typedata)index()Indexing the number of row. it can be use as id too (only work in int typedata)genID()Generate random 5 digits IDincrease()Increase from the last row value (Only work in int typedata)SelectTo select a table, use this following functiondb.select_row(table="<table_name>",col="name,age")parameterstatusdescriptiontable:strrequiredthe name of table that you want to selectcol:strrequiredthe column name that you want to select. it separated by comma. or you can usecol="*"if you want to select all comunswhere:stroptionalselect the specific row.as_json:booloptionalif you already define it in thesayuDBclass, you didn't need to do it again. the default isFalseWhereNow, if you want to select specific row, you can usewhereparameter for itEqual or not equal.as example, I want to selectArsybaifrom table.db.select_row(table="<table_name>",col="*",where="name=Arsybai")Otherwise, if you want to select row that isn'tArsybaiusewhere="name!=Arsybai"The return will look like thisnumbernameageaddress
-----------------------------------1Arsybai23Solo,Indonesia1RowscontainsIf you want to select row that contain someting. you can usecontain.
as example I want to select name that containpoidb.select_row(table="<table_name>",col="*",where="name contain poi")The return will look like thisnumbernameageaddress
-------------------------------------2Moepoi20Jakarta,Indonesia1RowsUsing multiple conditionas example I want to selectArsybaiwith age20db.select_row(table="<table_name>",col="*",where="name=Arsybai && age=20")The return will look like thisnumbernameageaddress
----------------------------0RowsNote : You can useAND ( && ),OR ( || )in multiple condition. also the space between && or || is requiredUpdateIf you want to update a row, use this following functiondb.update_row(table="<table_name>",set_="<column_name>=<value>",where="<column_name>=<value>")Note that update row isn't support multiple condition.Also you can update a row more efficienly withupdate_row_jsondb.update_row_json(table="<table_name>",set_={"<col1_name>":"<value1>","<col2_name>":"<value2>"},where="<col_name>=<value>")DeleteIf you want to delete some row, use this following function#to delete specific data that equal with some valuedb.delete_row(table="<table_name>",where="<col_name>=<value>")#to delete specific data that contain some valuedb.delete_row(table="<table_name>",where="<col_name> contain <value>")#to delete specific data with row numberdb.delete_row(table="<table_name>",where="row <number_of_row>")#to delete specific data between row numberdb.delete_row(table="<table_name>",where="row between <number_of_rowX>-<number_of_rowY>")Alter tableTo alter or updating some table, use this following function# to add a columndb.alter_table_add_column(table="<table_name>",col_name="<col_name>",datatypes="<datatype>")# to remove a columndb.alter_table_drop_column(table="<table_name>",col_name="<col_name>")# to rename a columndb.alter_table_rename_column(table="<table_name>",col="<column_to_rename>",to_="<rename_to>")Clear tableTo clear table use this following functiondb.clear_table(table="<table_name>")This will erase all rows data in the table.