-<nav><ul><li><a href="/">TinyBase</a></li><li><a href="/guides/">Guides</a></li><li><a href="/guides/schemas/">Schemas</a></li><li><a href="/guides/schemas/using-schematizers/">Using Schematizers</a></li></ul></nav><section class="s1" id="/guides/schemas/using-schematizers/" data-id="US2"><h1>Using Schematizers</h1><p>Schematizers provide a convenient way to convert schemas from popular validation libraries into TinyBase's <a href="/api/store/type-aliases/schema/tablesschema/"><code>TablesSchema</code></a> and <a href="/api/store/type-aliases/schema/valuesschema/"><code>ValuesSchema</code></a> formats.</p><p>Instead of manually writing TinyBase schemas, you can use your existing schemas from libraries like Zod, TypeBox, and Valibot, and convert them at runtime using a schematizer. The full list of supported schema systems and their entry points is as follows:</p><div class="table"><table><thead><tr><th>Library</th><th>Creation function</th></tr></thead><tbody><tr><td><a href="https://github.com/colinhacks/zod">Zod</a></td><td><a href="/api/schematizer-zod/functions/creation/createzodschematizer/"><code>createZodSchematizer</code></a></td></tr><tr><td><a href="https://github.com/sinclairzx81/typebox">TypeBox</a></td><td><a href="/api/schematizer-typebox/functions/creation/createtypeboxschematizer/"><code>createTypeBoxSchematizer</code></a></td></tr><tr><td><a href="https://github.com/valibot/valibot">Valibot</a></td><td><a href="/api/schematizer-valibot/functions/creation/createvalibotschematizer/"><code>createValibotSchematizer</code></a></td></tr><tr><td><a href="https://github.com/arktypeio/arktype">ArkType</a></td><td><a href="/api/schematizer-arktype/functions/creation/createarktypeschematizer/"><code>createArkTypeSchematizer</code></a></td></tr><tr><td><a href="https://github.com/jquense/yup">Yup</a></td><td><a href="/api/schematizer-yup/functions/creation/createyupschematizer/"><code>createYupSchematizer</code></a></td></tr><tr><td><a href="https://github.com/Effect-TS/effect">Effect Schema</a></td><td><a href="/api/schematizer-effect/functions/creation/createeffectschematizer/"><code>createEffectSchematizer</code></a></td></tr></tbody></table></div><p>The <a href="/api/schematizers/functions/creation/createcustomschematizer/"><code>createCustomSchematizer</code></a> function also allows you to create your own schematizer that convert from any schema system not supported directly by TinyBase.</p><p>The rest of this guide will cover the Zod schematizer, but the concepts are exactly the same for other schema systems. Take a look at the API documentation for the other schematizers for exact details.</p><h3 id="using-the-zod-schematizer">Using The Zod <a href="/api/schematizers/interfaces/schematizer/schematizer/"><code>Schematizer</code></a></h3><p>The Zod schematizer allows you to convert Zod schemas into TinyBase schemas. You create a schematizer with the <a href="/api/schematizer-zod/functions/creation/createzodschematizer/"><code>createZodSchematizer</code></a> function and then use its <a href="/api/schematizer-arktype/interfaces/schematizer/arktypeschematizer/methods/conversion/totablesschema/"><code>toTablesSchema</code></a> method and <a href="/api/schematizer-arktype/interfaces/schematizer/arktypeschematizer/methods/conversion/tovaluesschema/"><code>toValuesSchema</code></a> method to perform the conversion:</p><pre><code><span class="keyword">import</span> <span class="punctuation">{</span>createStore<span class="punctuation">}</span> <span class="keyword">from</span> <span class="string">'tinybase'</span><span class="punctuation">;</span>
0 commit comments