我如何生成uniqueidentifier

时间:2012-12-12 09:56:41

标签: javascript sqlite

我开发应用程序移动,我使用框架phonegap,和 我用来将数据插入本地数据库我的问题是怎么做 使用javascript为sqlite生成uniqueidentifier?

    CREATE TABLE foobar (id uniqueidentifier, foo text, bar text, PRIMARY 
    KEY (id)); 

    insert into foobar values (newid(), "Aaa", "Bbb"); 



    id                                        foo      bar 
    ___________________________________________________________ 

    {00000109-0000-0010-8000-00AA006D2EA4}    "Aaa"    "Bbb" 

1 个答案:

答案 0 :(得分:0)

您有不同的选择:

  1. 通过Broofa
  2. 取得compacted version
  3. 将{untid方法添加到Math对象中this version。然后只需调用Math.uuid()来生成随机UUID,也可以通过Broofa。
  4. A complete library对uuid进行多次操作,例如,您可以使用版本4(基于随机数)以及版本1(基于时间)。
  5. 要完成,正如评论中所说340,282,366,920,938,463,463,374,607,431,768,211,456 possible UUIDs,所以不要担心产生两倍相同,你将有更多机会尝试赢得10亿次彩票。