Skip to content
This repository was archived by the owner on Jan 23, 2022. It is now read-only.

Commit 7c61493

Browse files
committed
🎉 NEW: 0.1.0
1 parent 60562b1 commit 7c61493

File tree

12 files changed

+81
-48
lines changed

12 files changed

+81
-48
lines changed

.eslintrc.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,13 @@
44
"es2021": true,
55
"node": true
66
},
7-
"extends": [
8-
"eslint:recommended",
9-
"plugin:@typescript-eslint/recommended",
10-
"prettier",
11-
"@casper124578/eslint-config",
12-
"plugin:prettier/recommended"
13-
],
7+
"extends": ["@casper124578/eslint-config"],
148
"parser": "@typescript-eslint/parser",
159
"parserOptions": {
1610
"ecmaVersion": 12,
1711
"sourceType": "module"
1812
},
19-
"plugins": ["@typescript-eslint", "prettier"],
2013
"rules": {
21-
"prettier/prettier": ["error"],
22-
"@typescript-eslint/no-explicit-any": "off",
23-
"@typescript-eslint/explicit-module-boundary-types": "off",
2414
"prefer-rest-params": "off"
2515
}
2616
}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 0.1.0
4+
5+
- **BREAKING:** Remove `returnEmptyArrayForNoResults`
6+
- Bump dependencies
7+
- Format code
8+
39
## 0.0.20
410

511
- Make [`BuilderTypes`](https://github.com/Dev-CasperTheGhost/mysql.ts/blob/main/docs/BuilderTypes.md) options optional

docs/Query.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ const connection = await createConnection({
118118
/* ... */
119119
});
120120

121-
const result = await connection.query().select("*").from("books").whereLike("name", "%cool%").exec();
121+
const result = await connection
122+
.query()
123+
.select("*")
124+
.from("books")
125+
.whereLike("name", "%cool%")
126+
.exec();
122127
```
123128

124129
[Back to top](#methods)
@@ -130,7 +135,13 @@ const connection = await createConnection({
130135
/* ... */
131136
});
132137

133-
const result = await connection.query().select("*").from("books").where("id", "0").and("name", "my-cool-name").exec();
138+
const result = await connection
139+
.query()
140+
.select("*")
141+
.from("books")
142+
.where("id", "0")
143+
.and("name", "my-cool-name")
144+
.exec();
134145
```
135146

136147
[Back to top](#methods)
@@ -198,7 +209,11 @@ const result = await connection
198209
.exec();
199210

200211
// With chaining
201-
const result = await connection.query().raw("SELECT * FROM `books`").where("name", "cool-book-name").exec();
212+
const result = await connection
213+
.query()
214+
.raw("SELECT * FROM `books`")
215+
.where("name", "cool-book-name")
216+
.exec();
202217
```
203218

204219
[Back to top](#methods)

package-lock.json

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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@casper124578/mysql.ts",
3-
"version": "0.0.20",
3+
"version": "0.1.0",
44
"description": "A simple mysql wrapper for node.js",
55
"main": "dist/index.js",
66
"private": false,
@@ -46,10 +46,11 @@
4646
"typescript": "^4.2.4"
4747
},
4848
"prettier": {
49+
"endOfLine": "auto",
4950
"semi": true,
5051
"trailingComma": "all",
5152
"singleQuote": false,
52-
"printWidth": 120,
53+
"printWidth": 100,
5354
"tabWidth": 2
5455
}
5556
}

src/BuilderTypes.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,32 @@ import { QueryValue, BuilderTypeOptions } from "./types";
33
/**
44
* defaults: `nullable = true`, `length = 255`
55
*/
6-
export function string({ nullable = true, length = 255, DEFAULT }: BuilderTypeOptions = {}): string {
6+
export function string({
7+
nullable = true,
8+
length = 255,
9+
DEFAULT,
10+
}: BuilderTypeOptions = {}): string {
711
return `varchar(${length}) ${_returnNullable(nullable)} ${_returnDefault(DEFAULT)}`;
812
}
913

1014
/**
1115
* defaults: `nullable = true`, `length = 8`
1216
*/
13-
export function int({ nullable = true, length = 8, DEFAULT }: BuilderTypeOptions<number> = {}): string {
17+
export function int({
18+
nullable = true,
19+
length = 8,
20+
DEFAULT,
21+
}: BuilderTypeOptions<number> = {}): string {
1422
return `int(${length}) ${_returnNullable(nullable)} ${_returnDefault(DEFAULT)}`;
1523
}
1624

1725
/**
1826
* defaults: `nullable = true`
1927
*/
20-
export function text({ nullable = true, DEFAULT }: Omit<BuilderTypeOptions, "length"> = {}): string {
28+
export function text({
29+
nullable = true,
30+
DEFAULT,
31+
}: Omit<BuilderTypeOptions, "length"> = {}): string {
2132
return `text ${_returnNullable(nullable)} ${_returnDefault(DEFAULT)}`;
2233
}
2334

@@ -31,7 +42,10 @@ export function date({ nullable = true, DEFAULT }: Omit<BuilderTypeOptions, "len
3142
/**
3243
* defaults: `nullable = true`, `DEFAULT = {}`
3344
*/
34-
export function json({ nullable = true, DEFAULT = {} }: Omit<BuilderTypeOptions<any>, "length"> = {}) {
45+
export function json({
46+
nullable = true,
47+
DEFAULT = {},
48+
}: Omit<BuilderTypeOptions<any>, "length"> = {}) {
3549
return `JSON ${_returnNullable(nullable)} ${_returnDefault(DEFAULT)}`;
3650
}
3751

@@ -45,7 +59,10 @@ export function timestamp({ nullable = true, DEFAULT }: Omit<BuilderTypeOptions,
4559
/**
4660
* @see [https://github.com/Dev-CasperTheGhost/mysql.ts/blob/main/docs/BuilderTypes.md#customtype](https://github.com/Dev-CasperTheGhost/mysql.ts/blob/main/docs/BuilderTypes.md#customtype)
4761
*/
48-
export function customType<T = string>(type: string, { nullable = true, DEFAULT }: BuilderTypeOptions<T>) {
62+
export function customType<T = string>(
63+
type: string,
64+
{ nullable = true, DEFAULT }: BuilderTypeOptions<T>,
65+
) {
4966
return `${type} ${_returnNullable(nullable)} ${_returnDefault(DEFAULT as any)}`;
5067
}
5168

src/Connection.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ export class Connection<Tables> {
110110
}
111111

112112
private async addReconnectHandler(connection: mysql.Connection) {
113-
const ERROR_CODES = ["PROTOCOL_CONNECTION_LOST", "ECONNRESET", "PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR"];
113+
const ERROR_CODES = [
114+
"PROTOCOL_CONNECTION_LOST",
115+
"ECONNRESET",
116+
"PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR",
117+
];
114118

115119
connection.once("error", (err) => {
116120
if (ERROR_CODES.includes(err)) {

src/QueryBuilder.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export class QueryBuilder<Tables, T = any> {
5757
return `${(data as any)[key]}`;
5858
});
5959

60-
this.query += `INSERT INTO ${tableName} (${this.createKeys(data)}) VALUES (${this.createValues(data)}) `;
60+
this.query += `INSERT INTO ${tableName} (${this.createKeys(data)}) VALUES (${this.createValues(
61+
data,
62+
)}) `;
6163
this.values.push(...values);
6264

6365
return this;
@@ -220,7 +222,11 @@ export class QueryBuilder<Tables, T = any> {
220222
isbn: int({ nullable: false, length: 50 }),
221223
}).exec()
222224
*/
223-
createTable(name: string, primary: keyof T | undefined, columns: Partial<Record<keyof T, string>>) {
225+
createTable(
226+
name: string,
227+
primary: keyof T | undefined,
228+
columns: Partial<Record<keyof T, string>>,
229+
) {
224230
const primaryKey = primary ? `, PRIMARY KEY (${primary})` : "";
225231
const values = this.createTableValues(columns);
226232

@@ -233,7 +239,11 @@ export class QueryBuilder<Tables, T = any> {
233239
* same as `QueryBuilder#createTable` but only create the table if it doesn't exist
234240
* @see [https://github.com/Dev-CasperTheGhost/mysql.ts/blob/main/docs/Query.md#create-table](https://github.com/Dev-CasperTheGhost/mysql.ts/blob/main/docs/Query.md#create-table)
235241
*/
236-
createTableIfNotExists(name: string, primary: keyof T | undefined, columns: Partial<Record<keyof T, string>>) {
242+
createTableIfNotExists(
243+
name: string,
244+
primary: keyof T | undefined,
245+
columns: Partial<Record<keyof T, string>>,
246+
) {
237247
const primaryKey = primary ? `, PRIMARY KEY (${primary})` : "";
238248
const values = this.createTableValues(columns);
239249

@@ -279,7 +289,7 @@ export class QueryBuilder<Tables, T = any> {
279289
/**
280290
* execute the query
281291
*/
282-
async exec(options?: Omit<mysql.QueryOptions, "sql" | "values">): Promise<T[] | undefined> {
292+
async exec(options?: Omit<mysql.QueryOptions, "sql" | "values">): Promise<(T | undefined)[]> {
283293
if (this.config.debugExec === true) {
284294
console.info(`[mysql.ts]: Query: ${this.query}`);
285295
console.info("[mysql.ts]: Values: ", this.values);
@@ -299,13 +309,7 @@ export class QueryBuilder<Tables, T = any> {
299309
return reject(err);
300310
}
301311

302-
if (this.config.returnEmptyArrayForNoResults) {
303-
return resolve(results);
304-
} else {
305-
if (results.length <= 0) {
306-
return resolve(undefined);
307-
}
308-
}
312+
return resolve(results);
309313
});
310314
});
311315
}

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { QueryBuilder } from "./QueryBuilder";
88
* @see [https://github.com/mysqljs/mysql#connection-options](https://github.com/mysqljs/mysql#connection-options)
99
* @returns The connection
1010
*/
11-
export async function createConnection<Tables = any>(config: ConnectionConfig): Promise<Connection<Tables>> {
11+
export async function createConnection<Tables = any>(
12+
config: ConnectionConfig,
13+
): Promise<Connection<Tables>> {
1214
return new Connection<Tables>(config);
1315
}
1416

src/types.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ export interface ConnectionConfig extends MySQLConnectionConfig {
77
* this will show the full query & values when a query is executed with the `QueryBuilder#exec` method
88
*/
99
debugExec?: boolean;
10-
11-
/**
12-
* when no results are found for a query:
13-
*
14-
* `false` = return `undefined`
15-
*
16-
* `true` = returns an empty array
17-
*
18-
* @default false
19-
*/
20-
returnEmptyArrayForNoResults?: boolean;
2110
}
2211

2312
export interface StatisticsPacket {

0 commit comments

Comments
 (0)