( value: unknown, col: AnyColumn, provider: SQLProvider )
| 230 | * Parse from driver value |
| 231 | */ |
| 232 | export 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 |
no test coverage detected