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操作可以由两部分组成:

  1. 字符串查询

    ^{pr2}$ 在
  2. 执行条目

    result = execute(sql,('Andrew))
    
  3. 结果是可选的,因为有些操作是不需要获取数据的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文件

确认

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
来自偏移量的java JavaPairInputStream流   gzip Java TarInputStream读取tar的文件名。包含另一个tar的gz文件。gz文件   如何在Linux shell脚本中确定和使用实际的java路径   java请求太多FirebaseError   java错误json解析   java在localserver上发送安卓应用程序的输出   JavaSpring:启动和停止webapplication时更新DBtable条目   java如何使用JavaFX在矩形处设置文本?   java SQL查询在Hibernate中出现异常   java我无法使用javamail代码通过outlook(hotmail帐户)配置发送邮件,但在gmail中工作正常   java是不同的持久性。测试运行/JPA装置的xml属性   无头Eclipse的java导出战   使用ContentVersionStrategy的java Spring引导缓存禁止使用gzip进行资源压缩   java如何获取计算机的设备令牌?   图像文件的java ImageInfo不包含有效值   继承强制在Java中使用基类方法