deno.land / x / pg_mem@2.8.1 / execution / clean-results.ts

clean-results.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { nullIsh } from '../utils.ts';
export const JSON_NIL = Symbol('null');export const IS_PARTIAL_INDEXING = Symbol('partial_indexing');export const SELECT_ALL = Symbol('select *');

export function cleanResults(results: any[]): any { // ugly hack to turn jsonb nulls & partial indexed results into actual nulls // This will bite me someday ... but please dont judge me, I too try to have a life outside here 🤔 // The sane thing to do would be to refactor things & introduce a DBNULL value in pgmem // since the need of such DBNULL value could arise somehow on another type // see: // - `can select jsonb null` test in nulls.spec.ts // - `executes array multiple index incomplete indexing` test in operators.queries.spec.ts
function cleanObj(obj: any) { if (!obj || typeof obj !== 'object') { return; } for (const [k, v] of Object.entries(obj)) { if (v === JSON_NIL) { obj[k] = null; } else if (Array.isArray(v)) { if ((v as any)[IS_PARTIAL_INDEXING]) { obj[k] = null; } else { for (let i = 0; i < v.length; i++) { if (obj[i] === JSON_NIL) { obj[i] = null; } else { cleanObj(v); } } } } else { cleanObj(v); } } }
for (let i = 0; i < results.length; i++) { const sel = results[i][SELECT_ALL]; if (sel) { results[i] = sel(); } cleanObj(results[i]); } return results;}
pg_mem

Version Info

Tagged at
4 months ago