Skip to content

Commit e4854d7

Browse files
committed
moving docs
1 parent 37019e5 commit e4854d7

File tree

5 files changed

+52
-36
lines changed

5 files changed

+52
-36
lines changed

README.md

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,4 @@ db.close();
2020

2121
***This module is still a work in progress.***
2222

23-
By design, it was created as an SQL backend for interaction-based Discord bots built in [discord.js v13](https://discord.js.org/#/docs/discord.js/v13/general/welcome). It is intended to create more user-friendly, asynchronous query functions, which take in an "options" object as arguments, a practice inspired by discord.js.
24-
25-
While it can run any query asychronously, it currently only supports the following built-in query and expression functions:
26-
27-
## Queries
28-
29-
### Insert
30-
`insert({ table: string, columns?: string[], values: string[])`
31-
```javascript
32-
const id = '123456789';
33-
const username = 'user99';
34-
35-
await db.insert({
36-
table: 'users',
37-
columns: [ 'id', 'username' ],
38-
values: [ id, username ]
39-
});
40-
```
41-
42-
### Select
43-
### Update
44-
### Delete
45-
## Expressions
46-
- Boolean
47-
- Aggregate
48-
49-
## Future plans
50-
Presently, there are no plans to add functionality such as creating tables, attaching databases, etc. For now, I handle operations like that with [DB Browser](https://sqlitebrowser.org/), which is a great tool for managing tables and data in small SQLite3 databases.
23+
By design, it was created as an SQL backend for interaction-based Discord bots built in [discord.js v13](https://discord.js.org/#/docs/discord.js/v13/general/welcome). It is intended to create more user-friendly, asynchronous query functions, which take in an "options" object as arguments, a practice inspired by discord.js.

docs/DOCS.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
While it can run any query asychronously, it currently only supports the following built-in query and expression functions:
2+
3+
## Queries
4+
5+
### Base Options
6+
`{ file?: string, table?: string }`
7+
8+
Any query can be run with the `file` option, which represents the relative path to a database file. The database will be accessed dynamically during the query and will only remain open until its resolution. This is ideal for avoiding the clutter of synchronously accessing a database when only a single query needs to be run.
9+
10+
```javascript
11+
// No need to call db.open('./database.db') or db.close(). This query will handle that itself!
12+
const data = await db.select({ file: './database.db', all: true, from: 'table' });
13+
```
14+
15+
### Insert
16+
`insert({ into: string, columns?: string[], values: string[] })`
17+
18+
```javascript
19+
var id = '123456789';
20+
var username = 'user99';
21+
22+
await db.insert({
23+
into: 'users',
24+
columns: [ 'id', 'username' ],
25+
values: [ id, username ]
26+
});
27+
```
28+
29+
### Select
30+
### Update
31+
### Delete
32+
33+
## Expressions
34+
- Boolean
35+
- Aggregate
36+
37+
## Future plans
38+
Presently, there are no plans to add functionality such as creating tables, attaching databases, etc. For now, I handle operations like that with [DB Browser](https://sqlitebrowser.org/), which is a great tool for managing tables and data in small SQLite3 databases.

index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type QueryPromise = Promise<QueryRetval>;
88

99
interface BaseOptions {
1010
file?: string,
11+
table?: string
1112
}
1213

1314
interface RunOptions extends BaseOptions {
@@ -16,7 +17,7 @@ interface RunOptions extends BaseOptions {
1617
}
1718

1819
interface InsertOptions extends BaseOptions {
19-
table: string,
20+
into: string,
2021
columns?: string[],
2122
values: string[]
2223
}
@@ -39,7 +40,7 @@ interface UpdateOptions extends BaseOptions {
3940
}
4041

4142
interface DeleteOptions extends BaseOptions {
42-
table: string,
43+
from: string,
4344
where?: (string | Expression)[]
4445
}
4546

lib/queries.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ module.exports = {
4747
// Export database open/close functions (synchronous!)
4848
open, close,
4949

50+
print: function() {
51+
console.log(typeof db);
52+
},
53+
5054
/**
5155
* Asynchronous database query.
5256
* @param {RunOptions} options SQL statement

util/sqlstr.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ module.exports = {
88
* @returns {string}
99
*/
1010
insertStr: function(options) {
11-
if (!options.table || !options.values)
11+
if (!(options.table || options.into) || !options.values)
1212
throw new Error('No table or values specified.');
1313

14-
let stmt = `INSERT INTO ${options.table}`;
14+
let stmt = `INSERT INTO ${options.table ?? options.into}`;
1515

1616
if (options.columns)
1717
stmt += ` (${parseColumns(options.columns)})`;
@@ -29,13 +29,13 @@ module.exports = {
2929
if (!options.all && !options.columns)
3030
throw new Error('No columns specified.');
3131

32-
let stmt = options.all ? 'SELECT *\n' : 'SELECT ';
32+
let stmt = options.all ? 'SELECT *' : 'SELECT ';
3333
let whereClause = emptyClause;
3434

3535
if (options.columns)
3636
stmt += parseColumns(options.columns);
3737

38-
stmt += `\nFROM ${options.from}`;
38+
stmt += `\nFROM ${options.table ?? options.from}`;
3939

4040
if (options.where)
4141
whereClause = parseClause('WHERE', options.where);
@@ -74,10 +74,10 @@ module.exports = {
7474
* @returns {string}
7575
*/
7676
deleteStr: function(options) {
77-
if (!options.table)
77+
if (!(options.table || options.from))
7878
throw new Error('No table specified.');
7979

80-
let stmt = `DELETE FROM ${options.table}`;
80+
let stmt = `DELETE FROM ${options.table ?? options.from}`;
8181
let whereClause = emptyClause;
8282

8383
if (options.where)

0 commit comments

Comments
 (0)