Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add milliseconds to SQLite datetimes #12

Merged
merged 5 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 39 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
language: python
python:
# Supported versions
- pypy3
- 3.6
- 3.7
- 3.8
- 3.9
- pypy
# Unsupported from Python team
- 2.7
- pypy3
# Completely unsupported
- 3.4
- 3.5
- 3.6
# See:
# https://www.python.org/downloads/
# https://www.pypy.org/download_advanced.html

env:
- SQLALCHEMY_VER=">=0.9.0,<1.0.0" PIP_OPTS=""
# Supported versions
- SQLALCHEMY_VER=">=1.3.0,<1.4.0" PIP_OPTS=""
- SQLALCHEMY_VER=">=1.4.0,<1.5.0" PIP_OPTS=""
# Unsupported versions
- SQLALCHEMY_VER=">=1.0.0,<1.1.0" PIP_OPTS=""
- SQLALCHEMY_VER=">=1.1.0,<1.2.0" PIP_OPTS=""
- SQLALCHEMY_VER=">=1.2.0,<1.3.0" PIP_OPTS=""

matrix:
exclude:
# SQLAlchemy < 1.0.0 does not support psycopg2cffi as required by pypy
- python: pypy
env: SQLALCHEMY_VER=">=0.9.0,<1.0.0" PIP_OPTS=""
- python: pypy3
env: SQLALCHEMY_VER=">=0.9.0,<1.0.0" PIP_OPTS=""
# See: https://www.sqlalchemy.org/download.html

services:
- postgresql
- mysql

jobs:
exclude:
# No package of SQLAlchemy v1.4 for these Python versions
- python: 3.4
env: SQLALCHEMY_VER=">=1.4.0,<1.5.0" PIP_OPTS=""
- python: 3.5
env: SQLALCHEMY_VER=">=1.4.0,<1.5.0" PIP_OPTS=""

before_install:
- export PY=`python -c 'import sys; print("pypy" if hasattr(sys,"pypy_version_info") else "%d.%d" % sys.version_info[:2])'`
- export PY_VER=`python -c 'import sys; print("%d.%d" % sys.version_info[:2])'`
Expand All @@ -46,10 +59,22 @@ install:
pip install "SQLAlchemy $SQLALCHEMY_VER";
fi
- pip install -e .
- pip install pytest flake8 flake8-import-order
- pip install pytest-cov codecov
- pip install pytest codecov flake8 flake8-import-order
# pytest-cov 2.10.0 requires a pytest >= 4.6 which is not available in the Python 2.7 environment.
# Use an older version for it.
- if [[ "$PY_VER" = "2.7" && "$PY" != "pypy" ]]; then
pip install 'pytest-cov < 2.10.0';
else
pip install pytest-cov;
fi
# PyMySQL dropped support for Python 2.7 in version 1.0.0:
# https://github.com/PyMySQL/PyMySQL/blob/master/CHANGELOG.md#v100
# mysql-coonector-python did the same since version 8.0.24:
# https://dev.mysql.com/doc/connector-python/en/connector-python-versions.html
- if [[ "$PY" = "pypy" ]]; then
pip install psycopg2cffi pymysql;
pip install psycopg2cffi 'pymysql < 1.0.0';
elif [[ "$PY_VER" = "2.7" ]]; then
pip install psycopg2 'mysql-connector-python < 8.0.24';
else
pip install psycopg2 mysql-connector-python;
fi
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ SQLAlchemy-Utc

.. image:: https://badge.fury.io/py/SQLAlchemy-Utc.svg?
:target: https://pypi.python.org/pypi/SQLAlchemy-Utc
.. image:: https://travis-ci.org/spoqa/sqlalchemy-utc.svg?branch=master
:target: https://travis-ci.org/spoqa/sqlalchemy-utc
.. image:: https://travis-ci.com/spoqa/sqlalchemy-utc.svg?branch=master
:target: https://travis-ci.com/spoqa/sqlalchemy-utc
.. image:: https://codecov.io/github/spoqa/sqlalchemy-utc/coverage.svg?branch=master
:target: https://codecov.io/github/spoqa/sqlalchemy-utc?branch=master

Expand Down
7 changes: 6 additions & 1 deletion sqlalchemy_utc/now.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ def mysql_sql_utcnow(element, compiler, **kw):

@compiles(utcnow, 'sqlite')
def sqlite_sql_utcnow(element, compiler, **kw):
return "(DATETIME('NOW'))"
"""SQLite DATETIME('NOW') returns a correct `datetime.datetime` but does not
add milliseconds to it.

Directly call STRFTIME with the final %f modifier in order to get those.
"""
return r"(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW'))"


@compiles(utcnow, 'mssql')
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = pypy, py27, pypy3, py34, py35, py36
envlist = pypy, py27, pypy3, py34, py35, py36, py37, py38, py39
minversion = 1.6.0

[testenv]
Expand Down