@suss/sql 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +205 -0
- package/README.md +41 -0
- package/THIRD-PARTY-NOTICES.md +13 -0
- package/dist/index.cjs +22212 -0
- package/dist/index.d.cts +44 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +22199 -0
- package/package.json +56 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a SQL statement touches: which tables, which fields, and what it
|
|
3
|
+
* picks rows by.
|
|
4
|
+
*
|
|
5
|
+
* A pack that meets a query written as SQL rather than through an ORM
|
|
6
|
+
* hands the text here and gets the same shape its own recognizer would
|
|
7
|
+
* have produced. The statement is parsed rather than pattern-matched,
|
|
8
|
+
* so a join contributes every table it reads and a `WHERE` contributes
|
|
9
|
+
* a selector.
|
|
10
|
+
*
|
|
11
|
+
* A statement this cannot parse gives back nothing, which is what a
|
|
12
|
+
* reader that cannot settle something says everywhere else. The README
|
|
13
|
+
* says which dialects it reads and what it leaves out.
|
|
14
|
+
*/
|
|
15
|
+
/** One table a statement touches, and what it does to it. */
|
|
16
|
+
interface SqlAccess {
|
|
17
|
+
table: string;
|
|
18
|
+
kind: "read" | "write";
|
|
19
|
+
/** The fields the statement states, or `["*"]` for a whole row. */
|
|
20
|
+
fields: string[];
|
|
21
|
+
/** The fields it picks rows by. */
|
|
22
|
+
selector: string[];
|
|
23
|
+
}
|
|
24
|
+
interface SqlReadOptions {
|
|
25
|
+
/** Which dialect the statement is written in. */
|
|
26
|
+
dialect?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Every table a statement touches, or nothing when it cannot be read. */
|
|
29
|
+
declare function readSqlAccess(sql: string, options?: SqlReadOptions): SqlAccess[];
|
|
30
|
+
/**
|
|
31
|
+
* The SQL a tagged template states, with each interpolation written as
|
|
32
|
+
* a parameter. What a query interpolates is a value nearly every time,
|
|
33
|
+
* and a parameter is how the statement would carry one anyway, so the
|
|
34
|
+
* text parses as what it means.
|
|
35
|
+
*
|
|
36
|
+
* A caller that knows what an interpolation is passes it in
|
|
37
|
+
* `substitutions`, which is how a table interpolated as an object
|
|
38
|
+
* reaches the statement as its own name. An interpolation nobody can
|
|
39
|
+
* settle stays a parameter, and a statement that needed one somewhere a
|
|
40
|
+
* parameter cannot go reads as nothing.
|
|
41
|
+
*/
|
|
42
|
+
declare function sqlFromParts(parts: readonly string[], substitutions?: ReadonlyArray<string | null>): string;
|
|
43
|
+
|
|
44
|
+
export { type SqlAccess, type SqlReadOptions, readSqlAccess, sqlFromParts };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a SQL statement touches: which tables, which fields, and what it
|
|
3
|
+
* picks rows by.
|
|
4
|
+
*
|
|
5
|
+
* A pack that meets a query written as SQL rather than through an ORM
|
|
6
|
+
* hands the text here and gets the same shape its own recognizer would
|
|
7
|
+
* have produced. The statement is parsed rather than pattern-matched,
|
|
8
|
+
* so a join contributes every table it reads and a `WHERE` contributes
|
|
9
|
+
* a selector.
|
|
10
|
+
*
|
|
11
|
+
* A statement this cannot parse gives back nothing, which is what a
|
|
12
|
+
* reader that cannot settle something says everywhere else. The README
|
|
13
|
+
* says which dialects it reads and what it leaves out.
|
|
14
|
+
*/
|
|
15
|
+
/** One table a statement touches, and what it does to it. */
|
|
16
|
+
interface SqlAccess {
|
|
17
|
+
table: string;
|
|
18
|
+
kind: "read" | "write";
|
|
19
|
+
/** The fields the statement states, or `["*"]` for a whole row. */
|
|
20
|
+
fields: string[];
|
|
21
|
+
/** The fields it picks rows by. */
|
|
22
|
+
selector: string[];
|
|
23
|
+
}
|
|
24
|
+
interface SqlReadOptions {
|
|
25
|
+
/** Which dialect the statement is written in. */
|
|
26
|
+
dialect?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Every table a statement touches, or nothing when it cannot be read. */
|
|
29
|
+
declare function readSqlAccess(sql: string, options?: SqlReadOptions): SqlAccess[];
|
|
30
|
+
/**
|
|
31
|
+
* The SQL a tagged template states, with each interpolation written as
|
|
32
|
+
* a parameter. What a query interpolates is a value nearly every time,
|
|
33
|
+
* and a parameter is how the statement would carry one anyway, so the
|
|
34
|
+
* text parses as what it means.
|
|
35
|
+
*
|
|
36
|
+
* A caller that knows what an interpolation is passes it in
|
|
37
|
+
* `substitutions`, which is how a table interpolated as an object
|
|
38
|
+
* reaches the statement as its own name. An interpolation nobody can
|
|
39
|
+
* settle stays a parameter, and a statement that needed one somewhere a
|
|
40
|
+
* parameter cannot go reads as nothing.
|
|
41
|
+
*/
|
|
42
|
+
declare function sqlFromParts(parts: readonly string[], substitutions?: ReadonlyArray<string | null>): string;
|
|
43
|
+
|
|
44
|
+
export { type SqlAccess, type SqlReadOptions, readSqlAccess, sqlFromParts };
|