我正在使用 Alloy 在 Titanium studio 中创建一些模型。我希望某些列是 date
或 boolean
,但当我运行应用程序时它不接受它。
根据 the documentation :
The following data types are accepted and mapped to the appropriate SQLite type: string, varchar, int, tinyint, smallint, bigint, double, float, decimal, number, date, datetime and boolean.
但是当我运行我的应用程序时,我在控制台中收到此消息:
[WARN] : "date" is not a valid sqlite field, using TEXT instead
[WARN] : "date" is not a valid sqlite field, using TEXT instead
[WARN] : "boolean" is not a valid sqlite field, using INTEGER instead
[WARN] : "boolean" is not a valid sqlite field, using INTEGER instead
也许我的模型设置不正确?这是我的代码:
exports.definition = {
config: {
columns: {
"availability_end": "date",
"availability_start": "date",
"deleted": "boolean",
"duration": "integer",
"title": "text",
},
adapter: {
type: "sql",
collection_name: "videos"
}
},
/* the rest of the model definition... */
最佳答案
因为它不是有效的 SQLite 数据类型。 http://www.sqlite.org/datatype3.html
1.2 日期和时间数据类型
SQLite 没有为存储日期和/或时间预留的存储类。相反,SQLite 的内置日期和时间函数能够将日期和时间存储为 TEXT、REAL 或 INTEGER 值:
文本作为 ISO8601 字符串(“YYYY-MM-DD HH:MM:SS.SSS”)。 实际作为儒略日数字,自公元前 4714 年 11 月 24 日格林威治中午以来的天数。根据公历。 INTEGER 作为 Unix 时间,自 1970-01-01 00:00:00 UTC 以来的秒数。 应用程序可以选择以这些格式中的任何一种存储日期和时间,并使用内置的日期和时间函数在格式之间自由转换。
也许文档只是告诉您它会自动正确地映射它。也许它还会自动为您管理日期操作。
关于javascript - 为什么 Titanium 不接受日期作为 SQLite 中的列类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21600646/