Skip to main content

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:

  1. String query

    sql = """SELECT * FROM order_table WHERE username = %s"""
    
  2. Execute entries

    result = execute(sql,('Andrew))
    
  3. 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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gadgethiServerUtils-0.0.43-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file gadgethiServerUtils-0.0.43-py3-none-any.whl.

File metadata

  • Download URL: gadgethiServerUtils-0.0.43-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

Hashes for gadgethiServerUtils-0.0.43-py3-none-any.whl
Algorithm Hash digest
SHA256 78d20e6bf80fc6575ffcbde3024c4f972423375afbedb33a9ad755aa0d223c8c
MD5 573f04016010857ba8cb8c19c037b7ea
BLAKE2b-256 c176bc88b9143222ec05bd3d35119df0f299cb77325c32d5a9e4c143e1770968

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page