MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / deserialize

Function deserialize

packages/core/fumadb/src/schema/serialize.ts:232–266  ·  view source on GitHub ↗
(
  value: unknown,
  col: AnyColumn,
  provider: SQLProvider
)

Source from the content-addressed store, hash-verified

230 * Parse from driver value
231 */
232export function deserialize(
233 value: unknown,
234 col: AnyColumn,
235 provider: SQLProvider
236) {
237 if (value === null) return null;
238
239 if (
240 !supportJson.includes(provider) &&
241 col.type === "json" &&
242 typeof value === "string"
243 ) {
244 return JSON.parse(value);
245 }
246
247 if (
248 provider === "sqlite" &&
249 (col.type === "timestamp" || col.type === "date") &&
250 (typeof value === "number" || typeof value === "string")
251 ) {
252 return new Date(value);
253 }
254
255 if (col.type === "bool" && typeof value === "number") return value === 1;
256
257 if (col.type === "bigint" && value instanceof Uint8Array) {
258 return readBigInt64BE(value);
259 }
260
261 if (col.type === "binary" && value instanceof Uint8Array) {
262 return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
263 }
264
265 return value;
266}
267
268/**
269 * Encode to driver value

Callers 1

decodeResultFunction · 0.90

Calls 1

readBigInt64BEFunction · 0.85

Tested by

no test coverage detected