Recap

The last section covered the client engine, a dynamically generated library customized for your project. Before we begin, make sure your code generally syncs up with the project panel below.
PROJECT
config
develop.ts
plugins
app
pages
home.ts
views
home.tsx
plugin.ts
package.json
schema.idea
tsconfig.json
unocss.config.ts
develop.ts
home.ts
home.tsx
plugin.ts
package.json
schema.idea
tsconfig.json
unocss.config.ts
Copy
If you are all caught up, then you can proceed to the next section.

3. Database Engine

Before we can enable the default Stackpress toolkit backend, we need to create a database plugin. This plugin will be used by all plugins requiring interaction with a database ensuring the same connection will be used throughout the project.

3.1. Install PGLite

In the interest of staying focused on the task at hand, working with PGLite allows to quickly create a file based Postgres scaffold for testing purposes. Let's add the PGLite and query builder in like the following code.
Copy
This also adds the eventual to the plugin list so Stackpress can initialize it. Next, run or to get the required packages for this tutorial to be installed.
NOTE: Stackpress has SQL connection mappings for , ,, and NPM packages.

3.2. Database Connection

Next, from the project root, create a new file called with the following code.
Copy

3.3. Store Plugin

Now that a connection function is defined, let's work on the database plugin entry file. From the project root, create a new file called with the following code.
Copy
This file will be the entry point for the database plugin.

3.4. Populate Database

From the project root, create a new file called plugins/store/populate.ts with the following code.
Copy
Then update the file to include the event like the following code.
Copy
Last, run the following commands to push to and populate the database.
  1. 1. In Terminal, run
  2. 2. In Terminal, run
  3. 3. In Terminal, run
NOTE: The command generally triggers events on the command line.

3.5. Database Commands

Now that both the client and database engine is setup, the following commands can be used to manage the database.
CommandNotes
Creates a migrations folder in [cwd]/.build folder and generates an SQL file. It does not push these changes to the database.
Removes all rows from all tables in the database.
Pushes schema changes to the database.
Queries the database. ie.

3.6. Check Point

In case you got lost, you can sync up your code with the project panel below.
PROJECT
config
develop.ts
plugins
app
pages
home.ts
views
home.tsx
plugin.ts
store
connect.ts
populate.ts
plugin.ts
package.json
schema.idea
tsconfig.json
unocss.config.ts
develop.ts
home.ts
home.tsx
plugin.ts
connect.ts
populate.ts
plugin.ts
package.json
schema.idea
tsconfig.json
unocss.config.ts
Copy
The next section will show how to add the Stackpress context provider so views can consume the toolkit.