Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 7907:8e2446cdf6fa
mod_storage_sql: Make archive:append() to return the id (or key) as first return value
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 20 Feb 2017 01:26:03 +0100 |
parent | 7858:14fe60a65c69 |
child | 7909:428d4abee723 |
child | 8029:e859f279add4 |
comparison
equal
deleted
inserted
replaced
7906:aa6b036150eb | 7907:8e2446cdf6fa |
---|---|
185 function archive_store:append(username, key, value, when, with) | 185 function archive_store:append(username, key, value, when, with) |
186 if type(when) ~= "number" then | 186 if type(when) ~= "number" then |
187 when, with, value = value, when, with; | 187 when, with, value = value, when, with; |
188 end | 188 end |
189 local user,store = username,self.store; | 189 local user,store = username,self.store; |
190 return engine:transaction(function() | 190 local ok, key = engine:transaction(function() |
191 if key then | 191 if key then |
192 engine:delete("DELETE FROM `prosodyarchive` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, user or "", store, key); | 192 engine:delete("DELETE FROM `prosodyarchive` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, user or "", store, key); |
193 else | 193 else |
194 key = uuid.generate(); | 194 key = uuid.generate(); |
195 end | 195 end |
196 local t, value = assert(serialize(value)); | 196 local t, value = assert(serialize(value)); |
197 engine:insert("INSERT INTO `prosodyarchive` (`host`, `user`, `store`, `when`, `with`, `key`, `type`, `value`) VALUES (?,?,?,?,?,?,?,?)", host, user or "", store, when, with, key, t, value); | 197 engine:insert("INSERT INTO `prosodyarchive` (`host`, `user`, `store`, `when`, `with`, `key`, `type`, `value`) VALUES (?,?,?,?,?,?,?,?)", host, user or "", store, when, with, key, t, value); |
198 return key; | 198 return key; |
199 end); | 199 end); |
200 if not ok then return ok, key; end | |
201 return key; | |
200 end | 202 end |
201 | 203 |
202 -- Helpers for building the WHERE clause | 204 -- Helpers for building the WHERE clause |
203 local function archive_where(query, args, where) | 205 local function archive_where(query, args, where) |
204 -- Time range, inclusive | 206 -- Time range, inclusive |