javascript - 为什么 Titanium 不接受日期作为 SQLite 中的列类型?

标签 javascript sqlite titanium appcelerator titanium-alloy

我正在使用 Alloy 在 Titanium studio 中创建一些模型。我希望某些列是 dateboolean,但当我运行应用程序时它不接受它。

根据 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/

相关文章:

c# - SQL 查询找不到以 č、ć、š、ž 等开头的城市

android - 如何在捕获交易之前使用 Paypal 轻松更新订单?

javascript - Titanium 双击和单击事件处理程序

javascript - 如何停止无限循环?

javascript - JS Revealing Pattern 事件未定义问题

javascript - 我的 sidenav 颜色没有随着按钮(点击)而改变

android - 应用程序在平板电脑上运行良好,但在 google play 上找不到

javascript - 有什么方法可以在不触摸窗口或文档的情况下重定向?

javascript - 按字母顺序排列歌曲列表,不区分大小写

swift - 将任意长度的数组绑定(bind)到 SQLite 查询