feat: Truncate QB function
This commit is contained in:
parent
3f0b03c808
commit
a43ad15eab
2 changed files with 16 additions and 0 deletions
|
|
@ -46,6 +46,11 @@ class Round(Function):
|
|||
super().__init__("ROUND", term, decimal, **kwargs)
|
||||
|
||||
|
||||
class Truncate(Function):
|
||||
def __init__(self, term, decimal, **kwargs):
|
||||
super().__init__("TRUNCATE", term, decimal, **kwargs)
|
||||
|
||||
|
||||
GroupConcat = ImportMapper({db_type_is.MARIADB: GROUP_CONCAT, db_type_is.POSTGRES: STRING_AGG})
|
||||
|
||||
Match = ImportMapper({db_type_is.MARIADB: MATCH, db_type_is.POSTGRES: TO_TSVECTOR})
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from frappe.query_builder.functions import (
|
|||
GroupConcat,
|
||||
Match,
|
||||
Round,
|
||||
Truncate,
|
||||
UnixTimestamp,
|
||||
)
|
||||
from frappe.query_builder.utils import db_type_is
|
||||
|
|
@ -163,6 +164,11 @@ class TestCustomFunctionsMariaDB(FrappeTestCase):
|
|||
query = frappe.qb.from_(note).select(Round(note.price, 3))
|
||||
self.assertEqual("select round(`price`,3) from `tabnote`", str(query).lower())
|
||||
|
||||
def test_truncate(self):
|
||||
note = frappe.qb.DocType("Note")
|
||||
query = frappe.qb.from_(note).select(Truncate(note.price, 3))
|
||||
self.assertEqual("select truncate(`price`,3) from `tabnote`", str(query).lower())
|
||||
|
||||
|
||||
@run_only_if(db_type_is.POSTGRES)
|
||||
class TestCustomFunctionsPostgres(FrappeTestCase):
|
||||
|
|
@ -302,6 +308,11 @@ class TestCustomFunctionsPostgres(FrappeTestCase):
|
|||
query = frappe.qb.from_(note).select(Round(note.price, 3))
|
||||
self.assertEqual('select round("price",3) from "tabnote"', str(query).lower())
|
||||
|
||||
def test_truncate(self):
|
||||
note = frappe.qb.DocType("Note")
|
||||
query = frappe.qb.from_(note).select(Truncate(note.price, 3))
|
||||
self.assertEqual('select truncate("price",3) from "tabnote"', str(query).lower())
|
||||
|
||||
|
||||
class TestBuilderBase:
|
||||
def test_adding_tabs(self):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue