Gadgethi服务器维护包
gadgethiServerUtils的Python项目详细描述
小工具服务器实用程序
这是可以支持gadgethi服务器开发的实用程序助手函数。在
初始设置
需要设置配置位置参数
config_location = "/opt/doday/doday-config/server-config.yaml"
并调用generate-db-uheader
public pub pem密钥应位于/opt/doday/cert/*文件夹中
数据库操作
这是db_operations.py
文件的文档。在
抽象层次
db_operations是用于对数据库执行低级操作的实用函数
python PostgreSQL操作可以由两部分组成:
- 在
字符串查询
^{pr2}$ 在 - 在
执行条目
在result = execute(sql,('Andrew))
- 在
结果是可选的,因为有些操作是不需要获取数据的POST操作。在
在
数据库连接
PostgreSQL需要显式函数才能连接到数据库
连接心理2connect_to_database
POSTGRESQL连接数据库。在
通过传入test
参数=True
,服务器连接到测试数据库。在
生成查询
有四个主要的查询示例。如果每次都要打出来,我们可能会觉得很痛苦。在
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);'''
所以Andrew编写了generate_query
系列函数
Gerate查询函数generate_query
此函数用于泛化查询语句。在
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.
执行SQL
executeSql函数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.
版本控制
Gados-redbean-devel-v1.2.2
作者
- Andrew Wong
许可证
这个项目是在麻省理工学院许可下授权的-有关详细信息,请参阅LICENSE.md文件
确认
- 项目
标签: