Compare commits
3 commits
46ff56f0b4
...
6a1c444770
Author | SHA1 | Date | |
---|---|---|---|
6a1c444770 | |||
8985e25bac | |||
ad4652c874 |
1 changed files with 15 additions and 3 deletions
18
index.js
18
index.js
|
@ -77,6 +77,7 @@ async function get_counter_value(ns_name, key, return_id = false) {
|
|||
}
|
||||
|
||||
async function counter_increment(ns_name, key, offset, create = false) {
|
||||
if (!valid_regex.test(key) || !valid_regex.test(ns_name)) return null;
|
||||
var nsid = await get_namespace_id(ns_name);
|
||||
return await sql.begin(async (sql) => {
|
||||
if (offset == 0) return true;
|
||||
|
@ -133,11 +134,21 @@ async function counter_set(ns_name, key, value) {
|
|||
}
|
||||
|
||||
async function counter_info(ns_name, key) {
|
||||
if (!valid_regex.test(key) || !valid_regex.test(ns_name))
|
||||
return {
|
||||
id: null,
|
||||
namespace: null,
|
||||
name: null,
|
||||
value: null,
|
||||
enable_reset: null,
|
||||
update_lowerbound: null,
|
||||
update_upperbound: null,
|
||||
};
|
||||
var nsid = get_namespace_id(ns_name);
|
||||
if (nsid == null)
|
||||
return {
|
||||
id: null,
|
||||
namespace_id: null,
|
||||
namespace: null,
|
||||
name: null,
|
||||
value: null,
|
||||
enable_reset: null,
|
||||
|
@ -145,11 +156,11 @@ async function counter_info(ns_name, key) {
|
|||
update_upperbound: null,
|
||||
};
|
||||
var data =
|
||||
await sql`SELECT * FROM keys WHERE name = ${key} AND namespace_id = ${nsid}`;
|
||||
await sql`SELECT id, name, value, enable_reset, update_lowerbound, update_upperbound FROM keys WHERE name = ${key} AND namespace_id = ${nsid}`;
|
||||
if (data.length == 0)
|
||||
return {
|
||||
id: null,
|
||||
namespace_id: null,
|
||||
namespace: null,
|
||||
name: null,
|
||||
value: null,
|
||||
enable_reset: null,
|
||||
|
@ -158,6 +169,7 @@ async function counter_info(ns_name, key) {
|
|||
};
|
||||
var key = data[0];
|
||||
if (typeof key.value === "string") key.value = parseInt(key.value);
|
||||
key.namespace = ns_name;
|
||||
return key;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue