MCPcopy Create free account
hub / github.com/TanStack/db / toBindableValue

Function toBindableValue

packages/browser-db-sqlite-persistence/src/opfs-worker.ts:62–101  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

60}
61
62function toBindableValue(value: unknown): SQLiteCompatibleBinding {
63 if (value === null || value === undefined) {
64 return null
65 }
66
67 if (typeof value === `string`) {
68 return value
69 }
70
71 if (typeof value === `number`) {
72 return Number.isFinite(value) ? value : null
73 }
74
75 if (typeof value === `bigint`) {
76 return value
77 }
78
79 if (typeof value === `boolean`) {
80 return value ? 1 : 0
81 }
82
83 if (value instanceof Date) {
84 return value.toISOString()
85 }
86
87 if (value instanceof Uint8Array) {
88 return value
89 }
90
91 if (
92 Array.isArray(value) &&
93 value.every((entry) => typeof entry === `number` && Number.isFinite(entry))
94 ) {
95 return [...value]
96 }
97
98 throw new InvalidPersistedCollectionConfigError(
99 `Unsupported parameter type for wa-sqlite binding`,
100 )
101}
102
103function toErrorCode(error: unknown): BrowserOPFSWorkerErrorCode {
104 if (error instanceof PersistenceUnavailableError) {

Callers 1

executeSqlInWorkerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected