Goo*_*ert 2 python neo4j py2neo
这是我想在 BOLT 下运行并且能够在 py2neo 下执行的代码的简化示例
timeCreated = datetime.datetime(year=2016, month=6, day=15, hour=23)
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "password"))
session = driver.session()
stmt = 'CREATE (y:Year) SET y.timeCreated = {time}'
session.run(stmt, {"time": timeCreated})
Run Code Online (Sandbox Code Playgroud)
timeCreated 是 python datetime 对象。我收到一条错误消息,指出无法使用日期时间对象:
ValueError: Values of type <class 'datetime.datetime'> are not supported).
Run Code Online (Sandbox Code Playgroud)
有解决方法吗?将来会支持吗?我想使用 BOLT 驱动程序并减少对 py2Neo 的依赖,但似乎并非所有功能都可以转移。
Neo4j 本身不支持日期时间,我相信 py2neo 在以前的版本中默默地将日期时间转换为字符串。
我的解决方法是调用对象上的.isoformat()方法datetime将它们作为字符串插入到数据库中。
| 归档时间: |
|
| 查看次数: |
1251 次 |
| 最近记录: |