sqlalchemy.func.current_date - python examples

Here are the examples of the python api sqlalchemy.func.current_date taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

0 View Complete Implementation : util.py
Copyright Apache License 2.0
Author : rucio
def get_db_time():
    """ Gives the utc time on the db. """
    s = session.get_session()
    try:
        storage_date_format = None
        if s.bind.dialect.name == 'oracle':
            query = select([text("sys_extract_utc(systimestamp)")])
        elif s.bind.dialect.name == 'mysql':
            query = select([text("utc_timestamp()")])
        elif s.bind.dialect.name == 'sqlite':
            query = select([text("datetime('now', 'utc')")])
            storage_date_format = '%Y-%m-%d  %H:%M:%S'
        else:
            query = select([func.current_date()])

        for now, in s.execute(query):
            if storage_date_format:
                return datetime.strptime(now, storage_date_format)
            return now

    finally:
        s.remove()

0 View Complete Implementation : test_compiler.py
Copyright MIT License
Author : sqlalchemy
    def test_function_overrides(self):
        self.astert_compile(func.current_date(), "GETDATE()")
        self.astert_compile(func.length(3), "LEN(:length_1)")

0 View Complete Implementation : test_functions.py
Copyright MIT License
Author : sqlalchemy
    def test_conn_execute(self):
        from sqlalchemy.sql.expression import FunctionElement
        from sqlalchemy.ext.compiler import compiles

        clast myfunc(FunctionElement):
            type = Date()

        @compiles(myfunc)
        def compile_(elem, compiler, **kw):
            return compiler.process(func.current_date())

        conn = testing.db.connect()
        try:
            x = conn.execute(func.current_date()).scalar()
            y = conn.execute(func.current_date().select()).scalar()
            z = conn.scalar(func.current_date())
            q = conn.scalar(myfunc())
        finally:
            conn.close()
        astert (x == y == z == q) is True

0 View Complete Implementation : test_text.py
Copyright MIT License
Author : sqlalchemy
    def test_text_in_select_nonfrom(self):

        generate_series = text(
            "generate_series(:x, :y, :z) as s(a)"
        ).bindparams(x=None, y=None, z=None)

        s = select(
            [(func.current_date() + literal_column("s.a")).label("dates")]
        ).select_from(generate_series)

        self.astert_compile(
            s,
            "SELECT CURRENT_DATE + s.a AS dates FROM "
            "generate_series(:x, :y, :z) as s(a)",
            checkparams={"y": None, "x": None, "z": None},
        )

        self.astert_compile(
            s.params(x=5, y=6, z=7),
            "SELECT CURRENT_DATE + s.a AS dates FROM "
            "generate_series(:x, :y, :z) as s(a)",
            checkparams={"y": 6, "x": 5, "z": 7},
        )