fix: misc fixes

This commit is contained in:
Aradhya 2021-12-06 13:04:27 +05:30
parent fec76ba950
commit 3243fb2083
3 changed files with 21 additions and 34 deletions

View file

@ -511,14 +511,10 @@ class Database(object):
# Get coulmn and value of the single doctype Accounts Settings
account_settings = frappe.db.get_singles_dict("Accounts Settings")
"""
result = self.sql("""
SELECT field, value
FROM `tabSingles`
WHERE doctype = %s
""", doctype)
result = self.query.get_sql(
"Singles", filters={"doctype": doctype}, fields=["field", "value"]
).run()
dict_ = frappe._dict(result)
return dict_
@staticmethod
@ -547,8 +543,11 @@ class Database(object):
if fieldname in self.value_cache[doctype]:
return self.value_cache[doctype][fieldname]
val = self.sql("""select `value` from
`tabSingles` where `doctype`=%s and `field`=%s""", (doctype, fieldname))
val = self.query.get_sql(
table="Singles",
filters={"doctype": doctype, "field": fieldname},
fields="value",
).run()
val = val[0][0] if val else None
df = frappe.get_meta(doctype).get_field(fieldname)

View file

@ -286,14 +286,13 @@ class Query:
):
criterion = self.build_conditions(table, filters, **kwargs)
if isinstance(fields, (list, tuple)):
query = criterion.select(*kwargs.get("field_objects"))
query = criterion.select(*kwargs.get("field_objects", fields))
elif isinstance(fields, Criterion):
query = criterion.select(fields)
else:
if fields=="*":
query = criterion.select(fields)
query = criterion.select(fields)
return query

View file

@ -18,16 +18,6 @@ class Base:
table_name = get_table_name(table_name)
return Table(table_name, *args, **kwargs)
class MariaDB(Base, MySQLQuery):
Field = terms.Field
@classmethod
def from_(cls, table, *args, **kwargs):
if isinstance(table, str):
table = cls.DocType(table)
return super().from_(table, *args, **kwargs)
@classmethod
def into(cls, table, *args, **kwargs):
if isinstance(table, str):
@ -40,6 +30,17 @@ class MariaDB(Base, MySQLQuery):
table = cls.DocType(table)
return super().update(table, *args, **kwargs)
class MariaDB(Base, MySQLQuery):
Field = terms.Field
@classmethod
def from_(cls, table, *args, **kwargs):
if isinstance(table, str):
table = cls.DocType(table)
return super().from_(table, *args, **kwargs)
class Postgres(Base, PostgreSQLQuery):
field_translation = {"table_name": "relname", "table_rows": "n_tup_ins"}
schema_translation = {"tables": "pg_stat_all_tables"}
@ -69,15 +70,3 @@ class Postgres(Base, PostgreSQLQuery):
table = cls.DocType(table)
return super().from_(table, *args, **kwargs)
@classmethod
def into(cls, table, *args, **kwargs):
if isinstance(table, str):
table = cls.DocType(table)
return super().into(table, *args, **kwargs)
@classmethod
def update(cls, table, *args, **kwargs):
if isinstance(table, str):
table = cls.DocType(table)
return super().update(table, *args, **kwargs)