* rowToNode for rows that arrive as arrays, whose columns are in `columns` order. * Name and id lookups are most of what resolving a reference spends in SQLite, * and a row as an array costs about a third less to read than one as an object.
(columns: string[])
| 227 | * and a row as an array costs about a third less to read than one as an object. |
| 228 | */ |
| 229 | function arrayToNode(columns: string[]): (row: unknown[]) => Node { |
| 230 | const at = (column: keyof NodeRow): number => columns.indexOf(column); |
| 231 | const id = at('id'); |
| 232 | const kind = at('kind'); |
| 233 | const name = at('name'); |
| 234 | const qualifiedName = at('qualified_name'); |
| 235 | const filePath = at('file_path'); |
| 236 | const language = at('language'); |
| 237 | const startLine = at('start_line'); |
| 238 | const endLine = at('end_line'); |
| 239 | const startColumn = at('start_column'); |
| 240 | const endColumn = at('end_column'); |
| 241 | const docstring = at('docstring'); |
| 242 | const signature = at('signature'); |
| 243 | const visibility = at('visibility'); |
| 244 | const isExported = at('is_exported'); |
| 245 | const isAsync = at('is_async'); |
| 246 | const isStatic = at('is_static'); |
| 247 | const isAbstract = at('is_abstract'); |
| 248 | const decorators = at('decorators'); |
| 249 | const typeParameters = at('type_parameters'); |
| 250 | const returnType = at('return_type'); |
| 251 | const updatedAt = at('updated_at'); |
| 252 | return (row) => ({ |
| 253 | id: row[id] as string, |
| 254 | kind: row[kind] as NodeKind, |
| 255 | name: row[name] as string, |
| 256 | qualifiedName: row[qualifiedName] as string, |
| 257 | filePath: row[filePath] as string, |
| 258 | language: row[language] as Language, |
| 259 | startLine: row[startLine] as number, |
| 260 | endLine: row[endLine] as number, |
| 261 | startColumn: row[startColumn] as number, |
| 262 | endColumn: row[endColumn] as number, |
| 263 | docstring: (row[docstring] ?? undefined) as string | undefined, |
| 264 | signature: (row[signature] ?? undefined) as string | undefined, |
| 265 | visibility: row[visibility] as Node['visibility'], |
| 266 | isExported: row[isExported] === 1, |
| 267 | isAsync: row[isAsync] === 1, |
| 268 | isStatic: row[isStatic] === 1, |
| 269 | isAbstract: row[isAbstract] === 1, |
| 270 | decorators: row[decorators] ? safeJsonParse(row[decorators] as string, undefined) : undefined, |
| 271 | typeParameters: row[typeParameters] ? safeJsonParse(row[typeParameters] as string, undefined) : undefined, |
| 272 | returnType: (row[returnType] ?? undefined) as string | undefined, |
| 273 | updatedAt: row[updatedAt] as number, |
| 274 | }); |
| 275 | } |
| 276 | |
| 277 | /** A prepared `SELECT * FROM nodes …`, whose rows come back as nodes. */ |
| 278 | interface NodeStatement { |
no test coverage detected