array.ts — drizzle-orm Source File
Architecture documentation for array.ts, a typescript file in the drizzle-orm codebase. 0 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 130b9d90_0857_a430_5925_31f66ac4c0f5["array.ts"] f4f42b4c_8610_03dd_fe01_232098668127["common.ts"] f4f42b4c_8610_03dd_fe01_232098668127 --> 130b9d90_0857_a430_5925_31f66ac4c0f5 style 130b9d90_0857_a430_5925_31f66ac4c0f5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
function parsePgArrayValue(arrayString: string, startFrom: number, inQuotes: boolean): [string, number] {
for (let i = startFrom; i < arrayString.length; i++) {
const char = arrayString[i];
if (char === '\\') {
i++;
continue;
}
if (char === '"') {
return [arrayString.slice(startFrom, i).replace(/\\/g, ''), i + 1];
}
if (inQuotes) {
continue;
}
if (char === ',' || char === '}') {
return [arrayString.slice(startFrom, i).replace(/\\/g, ''), i];
}
}
return [arrayString.slice(startFrom).replace(/\\/g, ''), arrayString.length];
}
export function parsePgNestedArray(arrayString: string, startFrom = 0): [any[], number] {
const result: any[] = [];
let i = startFrom;
let lastCharIsComma = false;
while (i < arrayString.length) {
const char = arrayString[i];
if (char === ',') {
if (lastCharIsComma || i === startFrom) {
result.push('');
}
lastCharIsComma = true;
i++;
continue;
}
lastCharIsComma = false;
if (char === '\\') {
i += 2;
continue;
}
if (char === '"') {
const [value, startFrom] = parsePgArrayValue(arrayString, i + 1, true);
result.push(value);
i = startFrom;
continue;
}
if (char === '}') {
return [result, i + 1];
}
if (char === '{') {
const [value, startFrom] = parsePgNestedArray(arrayString, i + 1);
result.push(value);
i = startFrom;
continue;
}
const [value, newStartFrom] = parsePgArrayValue(arrayString, i, false);
result.push(value);
i = newStartFrom;
}
return [result, i];
}
export function parsePgArray(arrayString: string): any[] {
const [result] = parsePgNestedArray(arrayString, 1);
return result;
}
export function makePgArray(array: any[]): string {
return `{${
array.map((item) => {
if (Array.isArray(item)) {
return makePgArray(item);
}
if (typeof item === 'string') {
return `"${item.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
}
return `${item}`;
}).join(',')
}}`;
}
Domain
Subdomains
Imported By
Source
Frequently Asked Questions
What does array.ts do?
array.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, DatabaseDrivers subdomain.
What functions are defined in array.ts?
array.ts defines 4 function(s): makePgArray, parsePgArray, parsePgArrayValue, parsePgNestedArray.
What files import array.ts?
array.ts is imported by 1 file(s): common.ts.
Where is array.ts in the architecture?
array.ts is located at drizzle-orm/src/pg-core/utils/array.ts (domain: DrizzleORM, subdomain: DatabaseDrivers, directory: drizzle-orm/src/pg-core/utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free