Software /
code /
prosody
Comparison
plugins/mod_storage_sql2.lua @ 5894:9e47ece9457c
mod_storage_sql2: Switch to the util.sql table definition for the main table
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 31 Oct 2013 00:53:59 +0100 |
parent | 5893:62ce0328fdfe |
child | 5903:0e0aab930e10 |
comparison
equal
deleted
inserted
replaced
5893:62ce0328fdfe | 5894:9e47ece9457c |
---|---|
25 | 25 |
26 local engine; -- TODO create engine | 26 local engine; -- TODO create engine |
27 | 27 |
28 local function create_table() | 28 local function create_table() |
29 local Table,Column,Index = mod_sql.Table,mod_sql.Column,mod_sql.Index; | 29 local Table,Column,Index = mod_sql.Table,mod_sql.Column,mod_sql.Index; |
30 --[[ | 30 |
31 local ProsodyTable = Table { | 31 local ProsodyTable = Table { |
32 name="prosody"; | 32 name="prosody"; |
33 Column { name="host", type="TEXT", nullable=false }; | 33 Column { name="host", type="TEXT", nullable=false }; |
34 Column { name="user", type="TEXT", nullable=false }; | 34 Column { name="user", type="TEXT", nullable=false }; |
35 Column { name="store", type="TEXT", nullable=false }; | 35 Column { name="store", type="TEXT", nullable=false }; |
38 Column { name="value", type="MEDIUMTEXT", nullable=false }; | 38 Column { name="value", type="MEDIUMTEXT", nullable=false }; |
39 Index { name="prosody_index", "host", "user", "store", "key" }; | 39 Index { name="prosody_index", "host", "user", "store", "key" }; |
40 }; | 40 }; |
41 engine:transaction(function() | 41 engine:transaction(function() |
42 ProsodyTable:create(engine); | 42 ProsodyTable:create(engine); |
43 end);]] | |
44 | |
45 local create_sql = "CREATE TABLE `prosody` (`host` TEXT, `user` TEXT, `store` TEXT, `key` TEXT, `type` TEXT, `value` TEXT);"; | |
46 if params.driver == "PostgreSQL" then | |
47 create_sql = create_sql:gsub("`", "\""); | |
48 elseif params.driver == "MySQL" then | |
49 create_sql = create_sql:gsub("`value` TEXT", "`value` MEDIUMTEXT") | |
50 :gsub(";$", " CHARACTER SET 'utf8' COLLATE 'utf8_bin';"); | |
51 end | |
52 | |
53 local index_sql = "CREATE INDEX `prosody_index` ON `prosody` (`host`, `user`, `store`, `key`)"; | |
54 if params.driver == "PostgreSQL" then | |
55 index_sql = index_sql:gsub("`", "\""); | |
56 elseif params.driver == "MySQL" then | |
57 index_sql = index_sql:gsub("`([,)])", "`(20)%1"); | |
58 end | |
59 | |
60 local success,err = engine:transaction(function() | |
61 engine:execute(create_sql); | |
62 engine:execute(index_sql); | |
63 end); | 43 end); |
64 | 44 |
65 local ProsodyArchiveTable = Table { | 45 local ProsodyArchiveTable = Table { |
66 name="prosodyarchive"; | 46 name="prosodyarchive"; |
67 Column { name="sort_id", type="INTEGER", primary_key=true, auto_increment=true, nullable=false }; | 47 Column { name="sort_id", type="INTEGER", primary_key=true, auto_increment=true, nullable=false }; |