Moving things to use the common_route_params and unified functions for SQL enable and SQL LIMIT OFFSET
This commit is contained in:
@@ -1253,3 +1253,51 @@ def get_account_id_w_for_type_id(
|
||||
else: return False
|
||||
else: return None
|
||||
# ### END ### API DB SQL Methods ### get_account_id_w_for_type_id() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API DB SQL Methods ### sql_enable_part() ###
|
||||
# Updated 2022-01-17
|
||||
@logger_reset
|
||||
def sql_enable_part(table_name:str, enabled: str) -> bool|dict:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if not table_name: return False
|
||||
|
||||
if enabled in ['enabled', 'disabled', 'all']:
|
||||
log.info(f'Creating partial SQL string for "enabled" check. Enabled: {enabled}')
|
||||
if enabled == 'enabled':
|
||||
# sql = f'AND `person`.enable = :enable'
|
||||
sql = f'AND `{table_name}`.enable = true'
|
||||
enable = True
|
||||
elif enabled == 'disabled':
|
||||
# sql = f'AND `person`.enable = :enable'
|
||||
sql = f'AND `{table_name}`.enable = false'
|
||||
enable = False
|
||||
elif enabled == 'all':
|
||||
sql = f'AND (`{table_name}`.enable = true OR `{table_name}`.enable = false OR `{table_name}`.enable IS NULL)'
|
||||
enable = None
|
||||
|
||||
log.debug(sql)
|
||||
log.debug(enable)
|
||||
# return result
|
||||
return sql, enable
|
||||
else:
|
||||
return False
|
||||
# ### END ### API DB SQL Methods ### sql_enable_part() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API DB SQL Methods ### sql_limit_offset_part() ###
|
||||
# Updated 2022-01-17
|
||||
@logger_reset
|
||||
def sql_limit_offset_part(limit: int, offset: int = 0) -> bool|str:
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if limit >= 0 and offset >= 0:
|
||||
log.info(f'Creating partial SQL string for LIMIT and OFFSET. Limit: {limit}; Offset: {offset}')
|
||||
sql = f'LIMIT {limit} OFFSET {offset}'
|
||||
return sql
|
||||
else:
|
||||
return False
|
||||
# ### END ### API DB SQL Methods ### sql_limit_offset_part() ###
|
||||
|
||||
Reference in New Issue
Block a user