How do you trigger population of db on startup of app in SolidStart?

How do you trigger population of db on startup of app in SolidStart?
1 Reply
Joe Pea
Joe Pea16h ago
That's more like a "how do I use a database" question, not Solid specific. How you do that is really up to you. You can write code in your server entry point that will check if the DB has content, and if not the populate it. Start here where it describes the default files, including the server entry: https://docs.solidjs.com/solid-start/getting-started#project-files and see a description of the server entry: https://docs.solidjs.com/solid-start/reference/entrypoints/entry-server Or you can do a check for existing data in your server endpoints, if you prefer: https://docs.solidjs.com/solid-start/building-your-application/api-routes It's really up to you. It could look like this:
// entry-server.tsx

import { createHandler, StartServer } from "@solidjs/start/server";
import {getDatabaseValue, setDatabaseValue} from "some-database-lib"

const value = await getDatabaseValue('foo')

if (!value) await setDatabaseValue('foo', 'bar')

// continue as before:
export default createHandler(() => (
// ...Same as before...
))
// entry-server.tsx

import { createHandler, StartServer } from "@solidjs/start/server";
import {getDatabaseValue, setDatabaseValue} from "some-database-lib"

const value = await getDatabaseValue('foo')

if (!value) await setDatabaseValue('foo', 'bar')

// continue as before:
export default createHandler(() => (
// ...Same as before...
))
entry-server.tsx - Solid Docs
Documentation for SolidJS, the signals-powered UI framework
API routes - Solid Docs
Documentation for SolidJS, the signals-powered UI framework
Getting started - Solid Docs
Documentation for SolidJS, the signals-powered UI framework

Did you find this page helpful?