MCPcopy Create free account
hub / github.com/Seb-C/kiss-orm / compile

Method compile

src/Queries/SqlQuery.ts:57–81  ·  view source on GitHub ↗
(
		indexToPlaceholder: (i: number) => string,
		formatIdentifier: (s: string)=> string,
	)

Source from the content-addressed store, hash-verified

55 };
56
57 compile(
58 indexToPlaceholder: (i: number) => string,
59 formatIdentifier: (s: string)=> string,
60 ): CompiledQuery {
61 let sql = '';
62 const params: any[] = [];
63
64 const recursivelyAddParts = (parts: ReadonlyArray<QueryPart>) => {
65 for (let i = 0; i < parts.length; i++) {
66 if (parts[i] instanceof SqlQuery) {
67 recursivelyAddParts((<SqlQuery>parts[i]).parts);
68 } else if (parts[i] instanceof QueryParam) {
69 sql += indexToPlaceholder(params.length);
70 params.push((<QueryParam>parts[i]).param);
71 } else if (parts[i] instanceof QueryIdentifier) {
72 sql += formatIdentifier((<QueryIdentifier>parts[i]).identifier);
73 } else {
74 sql += parts[i];
75 }
76 }
77 };
78 recursivelyAddParts(this.parts);
79
80 return new CompiledQuery(sql, params);
81 }
82}

Callers 6

queryMethod · 0.80
queryMethod · 0.80
insertAndGetMethod · 0.80
queryMethod · 0.80
insertAndGetMethod · 0.80
SqlQuery.test.tsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected