Skip to content

Commit f3dc3a7

Browse files
committed
Add query types
1 parent dd68efe commit f3dc3a7

File tree

6 files changed

+58
-45
lines changed

6 files changed

+58
-45
lines changed

lib/queries.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,14 @@ module.exports = {
161161
open, close, get,
162162

163163
// Queries
164-
...queries, sync,
164+
165+
/**
166+
* @param {SelectionOptions} options
167+
* @returns
168+
*/
169+
select: async options => new Query(options).select(),
170+
171+
sync,
165172

166173
/**
167174
* Asynchronous delete query. Optional overload, since 'delete' is reserved keyword.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"tsd-jsdoc": "^2.5.0"
88
},
99
"types": "./types/index.d.ts",
10-
"name": "promisesql",
10+
"name": "promise-sql",
1111
"description": "A [node-sqlite3](https://www.npmjs.com/package/sqlite3) wrapper for running simple, promise-based database queries in Node.js. It works best in smaller projects with a lot of asynchronous development, e.g., a Discord bot that implements slash commands.",
1212
"version": "1.2.10",
13-
"main": "index.js",
13+
"main": "promise-sql.js",
1414
"directories": {
1515
"lib": "lib"
1616
},
File renamed without changes.

types/index.d.ts

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -55,51 +55,34 @@ declare module "util/string" {
5555
export function deleteStr(options: DeleteOptions): any;
5656
}
5757
declare module "lib/queries" {
58-
const _exports: {
59-
sync: typeof sync;
60-
/**
61-
* Asynchronous delete query. Optional overload, since 'delete' is reserved keyword.
62-
* @param {DeleteOptions} options
63-
* @returns {Promise<void>}
64-
*/
65-
delete: (options: DeleteOptions) => Promise<void>;
66-
constructor: Function;
67-
toString(): string;
68-
toLocaleString(): string;
69-
valueOf(): Object;
70-
hasOwnProperty(v: PropertyKey): boolean;
71-
isPrototypeOf(v: Object): boolean;
72-
propertyIsEnumerable(v: PropertyKey): boolean;
73-
simplifyOutput: (bit?: any) => boolean;
74-
open: typeof open;
75-
close: typeof close;
76-
get: typeof get;
77-
};
78-
export = _exports;
79-
/**
80-
* Synchronous query.
81-
* @param {Function} query
82-
* @param {string[]|BaseOptions} options
83-
* @returns {QueryRetval}
84-
*/
85-
function sync(query: Function, options?: string[] | BaseOptions): QueryRetval;
8658
/**
8759
* Opens a database file.
8860
* @param {string} file Relative path to the database file
8961
* @returns {void|never}
9062
*/
91-
function open(file: string): void | never;
63+
export function open(file: string): void | never;
9264
/**
9365
* Closes an open database.
9466
* @returns {void|never}
9567
*/
96-
function close(): void | never;
68+
export function close(): void | never;
9769
/**
9870
* Retrieves the database, if open.
9971
* @returns {PromiseDB|never}
10072
*/
101-
function get(): PromiseDB | never;
73+
export function get(): PromiseDB | never;
74+
/**
75+
* Synchronous query.
76+
* @param {Function} query
77+
* @param {string[]|BaseOptions} options
78+
* @returns {QueryRetval}
79+
*/
80+
export function sync(query: Function, options?: string[] | BaseOptions): QueryRetval;
10281
import { PromiseDB } from "lib/promisedb";
82+
export function simplifyOutput(bit?: any): boolean;
83+
export function select(options: SelectionOptions): Promise<SelectionPromise>;
84+
export function _delete(options: DeleteOptions): Promise<void>;
85+
export { _delete as delete };
10386
}
10487
declare module "lib/expressions/boolean" {
10588
export = booleanExpressions;
@@ -114,7 +97,7 @@ declare module "lib/operators/logic" {
11497
export const OR: string;
11598
export const NOT: string;
11699
}
117-
declare module "index" {
100+
declare module "promise-sql" {
118101
const _exports: {
119102
increment: (column: any) => string;
120103
decrement: (column: any) => string;
@@ -132,19 +115,13 @@ declare module "index" {
132115
OR: string;
133116
NOT: string;
134117
};
135-
sync: (query: Function, options?: any) => QueryRetval;
136-
delete: (options: DeleteOptions) => Promise<void>;
137-
constructor: Function;
138-
toString(): string;
139-
toLocaleString(): string;
140-
valueOf(): Object;
141-
hasOwnProperty(v: PropertyKey): boolean;
142-
isPrototypeOf(v: Object): boolean;
143-
propertyIsEnumerable(v: PropertyKey): boolean;
144118
simplifyOutput: (bit?: any) => boolean;
145119
open: (file: string) => void;
146120
close: () => void;
147121
get: () => import("lib/promisedb").PromiseDB;
122+
select: (options: SelectionOptions) => Promise<SelectionPromise>;
123+
sync: (query: Function, options?: string[] | BaseOptions) => QueryRetval;
124+
delete: (options: DeleteOptions) => Promise<void>;
148125
PromiseDB: typeof import("lib/promisedb").PromiseDB;
149126
};
150127
export = _exports;

types/index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/queryTypes.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
interface BooleanExpression {
2+
lhs: string,
3+
operator: string,
4+
rhs: string
5+
}
6+
7+
interface BaseOptions {
8+
file?: string,
9+
table?: string,
10+
}
11+
12+
interface RunOptions extends BaseOptions {
13+
statement: string,
14+
args?: any[]
15+
}
16+
17+
interface InsertOptions extends BaseOptions {
18+
into: string,
19+
columns?: string[],
20+
values: string[]
21+
}
22+
23+
interface SelectionOptions extends BaseOptions {
24+
first?: boolean,
25+
all?: boolean,
26+
columns?: string[],
27+
from: string,
28+
where?: (string | BooleanExpression)[]
29+
}

0 commit comments

Comments
 (0)