tinybase icon indicating copy to clipboard operation
tinybase copied to clipboard

Allow multiple types for cells in schema

Open skorphil opened this issue 9 months ago • 2 comments

Is your feature request related to a problem? Please describe. It is tupical scenario when some value can be of different types eg string | null. OK, tinyBase doesnt support null or undefined. That is why i'm using 0 for nullish data. But, i can't specify string | number type in schema:

export const persistentStateStore = createStore()
  .setValuesSchema({
    currentJournalDirectory: { type: "string" },
    selectedCurrency: { type: "string" },
  })
  .setValues({});

Describe the solution you'd like currentJournalDirectory: { type: ["string", "number"] }, or provide more native support for typings like: createStore<MySchemaType>() Ideally Zod integration, but that's another story

Describe alternatives you've considered IDK, use empty string but this would create mess in my data

skorphil avatar Mar 24 '25 15:03 skorphil

OK, good suggestion. Really want to improve schema support in v6.x

jamesgpearce avatar Mar 27 '25 17:03 jamesgpearce

OK, good suggestion. Really want to improve schema support in v6.x

I personally like how pouchDB made typings. Just: const db = new PouchDB<Type>("db") No custom schemas, no difficulties how to sync existing schema validation tool(like zod) with db typings. At the moment i had to completely redesign zod schema, create custom script to convert zod -> tinyDB etc... )))

skorphil avatar Mar 29 '25 14:03 skorphil