Rename methods for consistency
All checks were successful
/ prettier (pull_request) Successful in 16s
/ node-check (pull_request) Successful in 3s
/ tests (pull_request) Successful in 25s
/ boot (pull_request) Successful in 9s
/ node-check (push) Successful in 3s
/ prettier (push) Successful in 15s
/ boot (push) Successful in 14s
/ tests (push) Successful in 24s

This commit is contained in:
Firepup Sixfifty 2024-06-01 20:13:58 +00:00
parent 57a6494261
commit b9f41165e0
Signed by: Firepup650
GPG key ID: 32DA8485D9E8ED07

View file

@ -32,7 +32,7 @@ async function get_namespace_id(name, create = true) {
}
});
}
async function add_counter(opts) {
async function counter_create(opts) {
const {
key,
value,
@ -68,7 +68,7 @@ async function add_counter(opts) {
}
}
async function get_counter_value(ns_name, key, return_id = false) {
async function counter_get(ns_name, key, return_id = false) {
const nsid = await get_namespace_id(ns_name, false);
if (nsid == null) {
if (!return_id) return null;
@ -98,7 +98,7 @@ async function counter_increment(ns_name, key, offset, create = false) {
await sql`SELECT value FROM keys WHERE name = ${key} AND namespace_id = ${nsid}`;
if (existence_res.length == 0) {
if (
!(await add_counter({
!(await counter_create({
namespace: ns_name,
key: key,
value: 1,
@ -137,7 +137,7 @@ async function counter_update(ns_name, key, amount) {
}
async function counter_set(ns_name, key, value) {
var { old_val: value, nsid } = await get_counter_value(ns_name, key, true);
var { old_val: value, nsid } = await counter_get(ns_name, key, true);
if (old_val == null) return { old_value: null, value: null, failed: true };
return await sql.begin(async (sql) => {
var changeable = (
@ -208,7 +208,7 @@ app.get("/hit/:key", async function (req, res) {
.json({ value: counter_res });
});
app.get("/update/:ns/:key", async function (req, res) {
var old_val = await get_counter_value(req.params.ns, req.params.key);
var old_val = await counter_get(req.params.ns, req.params.key);
var counter_res = await counter_increment(
req.params.ns,
req.params.key,
@ -221,7 +221,7 @@ app.get("/update/:ns/:key", async function (req, res) {
.json({ value: counter_res });
});
app.get("/update/:key", async function (req, res) {
var old_val = await get_counter_value("default", req.params.key);
var old_val = await counter_get("default", req.params.key);
var counter_res = await counter_increment(
"default",
req.params.key,
@ -274,11 +274,11 @@ app.get("/info/:key", async function (req, res) {
return res.status(e.value == null ? 404 : 200).json(e);
});
app.get("/get/:ns/:key", async function (req, res) {
var e = await get_counter_value(req.params.ns, req.params.key);
var e = await counter_get(req.params.ns, req.params.key);
return res.status(e == null ? 404 : 200).json({ value: e });
});
app.get("/get/:key", async function (req, res) {
var e = await get_counter_value("default", req.params.key);
var e = await counter_get("default", req.params.key);
return res.status(e == null ? 404 : 200).json({ value: e });
});
app.get("/create", async function (req, res) {
@ -292,8 +292,8 @@ app.get("/create", async function (req, res) {
if (!sane_query?.update_lowerbound) sane_query.update_lowerbound = "-1";
if (!sane_query?.update_upperbound) sane_query.update_upperbound = "1";
if (!sane_query?.value) sane_query.value = "0";
const add_counter_res = await add_counter(sane_query);
if (add_counter_res == true) {
const counter_create_res = await counter_create(sane_query);
if (counter_create_res == true) {
return res.json({
namespace: sane_query.namespace,
key: sane_query.key,