Skip to content

Commit f637797

Browse files
author
Snowflake107
committed
prettier
1 parent 273c7d5 commit f637797

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devsnowflake/jsql",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Use JSON as SQL.",
55
"main": "index.js",
66
"types": "typings/index.d.ts",

src/jsql/Database.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const handlers = {
66
insert: require('../util/methods/insert'),
77
drop: require('../util/methods/drop'),
88
update: require('../util/methods/update'),
9-
delete: require("../util/methods/delete"),
9+
delete: require('../util/methods/delete'),
1010
};
1111

1212
class Database {

src/util/Util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ module.exports = {
33
const nm = [];
44
for (let i = 0; i < arr.length; i += len) nm.push(arr.slice(i, i + len));
55
return nm;
6-
}
7-
};
6+
},
7+
};

src/util/methods/delete.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { chunk } = require("../Util");
1+
const { chunk } = require('../Util');
22

33
module.exports = (ast, db) => {
44
if (ast.type.toLowerCase() !== 'delete') throw new TypeError('invalid query type');
@@ -7,33 +7,33 @@ module.exports = (ast, db) => {
77
if (!data[table]) throw new Error(`Table "${table}" does not exist`);
88

99
const point = { left: ast.where.left.value, op: ast.where.operator, right: ast.where.right.value };
10-
if (!data[table].keys.some(x => x.column === point.left)) throw new Error(`Column "${set.col}" does not exists in table "${table}"`);
10+
if (!data[table].keys.some((x) => x.column === point.left)) throw new Error(`Column "${set.col}" does not exists in table "${table}"`);
1111
const bin = binOp(data[table], point);
1212
if (bin.index < 0) return;
1313

14-
bin.data.forEach(d => {
14+
bin.data.forEach((d) => {
1515
data[table].data.splice(data[table].data.indexOf(d), 1);
1616
});
1717

1818
db.write(data);
19-
}
19+
};
2020

2121
function binOp(data, clause) {
2222
switch (clause.op) {
23-
case "=":
23+
case '=':
2424
const child = chunk(data.data, 2);
25-
const fnx = m => m.key === clause.left && m.data === clause.right;
26-
const fn = x => x.find(fnx);
25+
const fnx = (m) => m.key === clause.left && m.data === clause.right;
26+
const fn = (x) => x.find(fnx);
2727

2828
try {
2929
const data = child.find(fn);
3030
if (!data) throw new Error(`Could not verify operation "${clause.left} = ${clause.right}"`);
3131
return {
3232
data: data,
33-
index: child.findIndex(fn)
33+
index: child.findIndex(fn),
3434
};
3535
} catch {
3636
throw new Error(`Could not verify operation "${clause.left} = ${clause.right}"`);
3737
}
3838
}
39-
}
39+
}

src/util/methods/select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { chunk } = require("../Util");
1+
const { chunk } = require('../Util');
22

33
module.exports = (ast, db) => {
44
if (ast.type.toLowerCase() !== 'select') throw new TypeError('invalid query type');

src/util/methods/update.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
const { chunk } = require("../Util");
1+
const { chunk } = require('../Util');
22

33
module.exports = (ast, db) => {
44
if (ast.type.toLowerCase() !== 'update') throw new TypeError('invalid query type');
55
const table = ast.table[0].table;
66
const data = db.db;
77
if (!data[table]) throw new Error(`Table "${table}" does not exist`);
8-
8+
99
const set = { col: ast.set[0].column, val: ast.set[0].value.value };
1010
const point = { left: ast.where.left.value, op: ast.where.operator, right: ast.where.right.value, set };
11-
if (!data[table].keys.some(x => x.column === set.col)) throw new Error(`Column "${set.col}" does not exists in table "${table}"`);
11+
if (!data[table].keys.some((x) => x.column === set.col)) throw new Error(`Column "${set.col}" does not exists in table "${table}"`);
1212
const bin = binOp(data[table], point);
1313
if (bin.index < 0) return;
1414

1515
const dataAt = data[table].data[bin.index + bin.idx];
1616
data[table].data.splice(bin.index + bin.idx, 1, {
1717
...dataAt,
18-
data: set.val
18+
data: set.val,
1919
});
2020

2121
db.write(data);
22-
}
22+
};
2323

2424
function binOp(data, clause) {
25-
switch(clause.op) {
26-
case "=":
25+
switch (clause.op) {
26+
case '=':
2727
const child = chunk(data.data, 2);
28-
const fnx = m => m.key === clause.left && m.data === clause.right;
29-
const fn = x => x.find(fnx);
28+
const fnx = (m) => m.key === clause.left && m.data === clause.right;
29+
const fn = (x) => x.find(fnx);
3030

3131
try {
3232
return {
3333
data: child.find(fn),
3434
index: child.findIndex(fn),
35-
idx: child.find(fn).findIndex(x => x.key === clause.set.col)
35+
idx: child.find(fn).findIndex((x) => x.key === clause.set.col),
3636
};
3737
} catch {
3838
throw new Error(`Could not verify operation "${clause.left} = ${clause.right}"`);
3939
}
4040
}
41-
}
41+
}

0 commit comments

Comments
 (0)