Gadgethi server maintenance package
Project description
gadgethiServerUtils
This is the utility helper functions that can support the gadgethi server development.
Initial setup
Need to setup config_location parameter
config_location = "/opt/doday/doday-config/server-config.yaml"
and call generate_db_header
public pub pem key should be in /opt/doday/cert/* folder
Database Operations
This is the documentation for db_operations.py file.
Abstract Level
db_operations is the utility function used for performing low-level operations on database
A python PostgreSQL operation may consists of two parts:
-
String query
sql = """SELECT * FROM order_table WHERE username = %s""" -
Execute entries
result = execute(sql,('Andrew)) -
Result would be optional, since some operations are POST actions that do not require fetching data.
Database Connection
PostgreSQL requires explicit functions to connect to database
Connection Psycopg2 connect_to_database
This function connects to the POSTGRESQL database.
By passing in test argument = True, the server connects to Test database.
Generate Query
There are four main query examples. We may find it painful if we have to type them all everytime.
Select = '''SELECT * FROM queue_table WHERE order_id = %s ORDER BY priority,time;'''
Update = '''UPDATE queue_table SET base = %s, soup = %s, main = %s, food1 = %s, food2 = %s, food3 = %s, special = %s, price = %s, discounted_price = %s ,promotion = %s, promotion_key = %s, priority = %s, status = %s WHERE order_id = %s;'''
Delete = '''DELETE FROM queue_table WHERE order_id = %s ;'''
Insert = '''INSERT into queue_table (order_id, order_no, base, soup, main, food1, food2, food3, special, price, discounted_price, promotion, promotion_key, priority, status, time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'''
So Andrew wrote the generate_query series functions
Gerate Query Function generate_query
This function generalizes the query statements.
generate_query(table, action, target_column_list, conditional_column_list = 'None', order_by_list = 'None', limit_number = 'None'):
* required:
- table: table to execute on (ex. 'order')
- action: A valid psycopg2 command (ex. 'SELECT')
- target_column_list: list of the column names after the ACTION statements (ex.['base','soup','food1']), SELECT * from order_tables means to select everything from order_table. In this case the target column list if the all_order_columns
* optionals:
- conditional_column_list: list of the column names after the WHERE statement (ex. [username, store_id]), WHERE username = %s, store_id = %s. In this case we want to find the arguments that match.
- order_by_list: Order by what ascending/descending order (ex.[priority DESC, time ASC, _id ASC]) Which means ORDER BY priority DESC, time ASC, _id ASC.
- limit_number: the number of fetched data you want (ex.1) limit 1.
* Returns:
- table_action_query: the query you want.
Execute SQL
executeSql Function executeSql
def executeSql(db_path, sql, entries, mode, debug_print=False, header=False):
* required:
- db_path: database path (ex.getDb('order))
- sql: string generated from the previous generate_query function
- entries: arguments matching the sql = %s parts, in tuple form
- mode:
mode = 0 -> normal execute
mode = 1 -> execute with arguments
mode = 2 -> with return values but without arguments
mode = 3 -> with return values and with arguments
* optionals:
- debug_print: True if development mode. Default False
- header: description for the command generated. Default False
* Returns:
- ret: Response of the execute command.
Versioning
Gados-redbean-devel-v1.2.2
Authors
- Andrew Wong
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Acknowledgments
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 Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gadgethiServerUtils-0.0.38-py3-none-any.whl.
File metadata
- Download URL: gadgethiServerUtils-0.0.38-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.20.1 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72371e978d7641ca1fc378f1c17b44b816dc68099d5ac75f162c017f6cc109ae
|
|
| MD5 |
781a0086a55896d1739b53eb891b0d35
|
|
| BLAKE2b-256 |
271e0021e8ce9bd4498042a49ddd745721ec78cb7d5027b60b0c780c56fb4497
|