gpt4 book ai didi

sqlite - 如何让 sqlalchemy 在 sqlite 中将日期时间存储为 julianday?

转载 作者:行者123 更新时间:2023-12-03 17:01:21 25 4
gpt4 key购买 nike

我不喜欢 SQLAlchemy 使用 sqlite 数据库处理日期时间值的方式。它以纯字符串格式存储值。同时sqlite推荐使用julianday来存储datetime值。

这里有没有简单的方法来改变 SQLAlchemy 的行为?

附言。我应该担心吗?可能没有人处理 julianday 只是因为它没有必要吗?

最佳答案

实际上,将日期存储为纯字符串的不是 SQLAlchemy; SQLite 本身 does not support date types .从一开始就明白这一点很重要; Sqlite 做 provide some functions用于处理日期,但这些日期存储为文本。这就是为什么 SQLAlchemy 在将日期与 Python 的日期时间类型相互转换方面发挥了一些魔力:根据 SQLAlchemy's documentation :

SQLite does not have built-in DATE, TIME, or DATETIME types, and pysqlite does not provide out of the box functionality for translating values between Python datetime objects and a SQLite-supported format. SQLAlchemy’s own DateTime and related types provide date formatting and parsing functionality when SQlite is used. The implementation classes are SLDateTime, SLDate and SLTime. These types represent dates and times as ISO formatted strings, which also nicely support ordering. There’s no reliance on typical “libc” internals for these functions so historical dates are fully supported.

至于使用儒略历而不是公历。你确定你想要那个吗?您是指公历日期吗?

关于sqlite - 如何让 sqlalchemy 在 sqlite 中将日期时间存储为 julianday?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1385393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com