mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add typings for sqlstring
This commit is contained in:
parent
737e62220e
commit
f0228785a5
9
types/sqlstring/index.d.ts
vendored
Normal file
9
types/sqlstring/index.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// Type definitions for sqlstring 2.2
|
||||
// Project: https://github.com/mysqljs/sqlstring
|
||||
// Definitions by: Marvin Hagemeister <https://github.com/marvinhagemeister>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
export function format(sql: string, args: object | any[]): string;
|
||||
export function escape(value: any): string;
|
||||
export function escapeId(value: any, dotQualifier?: boolean): string;
|
||||
31
types/sqlstring/sqlstring-tests.ts
Normal file
31
types/sqlstring/sqlstring-tests.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import * as SqlString from "sqlstring";
|
||||
|
||||
// Code samples taken from:
|
||||
// https://github.com/mysqljs/sqlstring/blob/master/README.md
|
||||
|
||||
const userId = "some user provided value";
|
||||
const sql1 = "SELECT * FROM users WHERE id = " + SqlString.escape(userId);
|
||||
|
||||
const userId2 = 1;
|
||||
const sql2 = SqlString.format("SELECT * FROM users WHERE id = ?", [userId2]);
|
||||
|
||||
const userId3 = 1;
|
||||
const sql3 = SqlString.format(
|
||||
"UPDATE users SET foo = ?, bar = ?, baz = ? WHERE id = ?",
|
||||
["a", "b", "c", userId3],
|
||||
);
|
||||
|
||||
const post = { id: 1, title: "Hello MySQL" };
|
||||
const sql4 = SqlString.format("INSERT INTO posts SET ?", post);
|
||||
|
||||
const sorter = "date";
|
||||
const sql5 =
|
||||
"SELECT * FROM posts ORDER BY " + SqlString.escapeId("posts." + sorter);
|
||||
|
||||
const sorter2 = "date.2";
|
||||
const sql6 =
|
||||
"SELECT * FROM posts ORDER BY " + SqlString.escapeId(sorter2, true);
|
||||
|
||||
const userId4 = 1;
|
||||
const inserts = ["users", "id", userId4];
|
||||
const sql7 = SqlString.format("SELECT * FROM ?? WHERE ?? = ?", inserts);
|
||||
22
types/sqlstring/tsconfig.json
Normal file
22
types/sqlstring/tsconfig.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"sqlstring-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/sqlstring/tslint.json
Normal file
1
types/sqlstring/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user