perf: prebuild types for type checking
This commit is contained in:
parent
fd29e9c464
commit
8192a87d00
1 changed files with 6 additions and 4 deletions
|
|
@ -13,7 +13,7 @@ from contextlib import contextmanager, suppress
|
|||
from time import time
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from pypika.dialects import MySQLQueryBuilder, PostgreSQLQueryBuilder, SQLLiteQueryBuilder
|
||||
from pypika.queries import QueryBuilder
|
||||
|
||||
import frappe
|
||||
import frappe.defaults
|
||||
|
|
@ -48,6 +48,8 @@ if TYPE_CHECKING:
|
|||
from pymysql.connections import Connection as MariadbConnection
|
||||
from pymysql.cursors import Cursor as MariadbCursor
|
||||
|
||||
ALLOWED_TYPES_FOR_VALUES = tuple | list | dict
|
||||
|
||||
IFNULL_PATTERN = re.compile(r"ifnull\(", flags=re.IGNORECASE)
|
||||
INDEX_PATTERN = re.compile(r"\s*\([^)]+\)\s*")
|
||||
SINGLE_WORD_PATTERN = re.compile(r'([`"]?)(tab([A-Z]\w+))\1')
|
||||
|
|
@ -213,7 +215,7 @@ class Database:
|
|||
{"name": "a%", "owner":"test@example.com"})
|
||||
|
||||
"""
|
||||
if isinstance(query, MySQLQueryBuilder | PostgreSQLQueryBuilder | SQLLiteQueryBuilder):
|
||||
if isinstance(query, QueryBuilder):
|
||||
frappe.log("Use run method to execute SQL queries generated by Query Builder")
|
||||
|
||||
debug = debug or getattr(self, "debug", False)
|
||||
|
|
@ -248,7 +250,7 @@ class Database:
|
|||
|
||||
if values == EmptyQueryValues:
|
||||
values = None
|
||||
elif not isinstance(values, tuple | dict | list):
|
||||
elif not isinstance(values, ALLOWED_TYPES_FOR_VALUES):
|
||||
values = (values,)
|
||||
|
||||
query, values = self._transform_query(query, values)
|
||||
|
|
@ -568,7 +570,7 @@ class Database:
|
|||
|
||||
row = result[0]
|
||||
|
||||
if len(row) > 1 or as_dict:
|
||||
if as_dict or len(row) > 1:
|
||||
return row
|
||||
# single field is requested, send it without wrapping in containers
|
||||
return row[0]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue