Database
Add a database to the App from Your First Route, then use it to store photo metadata. GoForj derives the model and repository from the schema you apply.
Enable SQLite
For the Quickstart Project, stop forj dev and add database_sqlite to the existing render.components list in .goforj.yml. Keep the other Project settings.
render:
components: [cli, web_api, database_sqlite]From the Project root, render the database support and check the default connection settings.
forj render &&
forj db --method local --printWith the default SQLite settings, the second command prints sqlite3 _data/sqlite/app.db. For a new Project, select Database (SQLite) in forj new. If your App already has SQLite, continue with the migration.
Add a Database-Backed Feature
- Create and apply a migration for a
photostable. - Generate a model and repository from the table and add a query.
- Test the query against a disposable SQLite file.
- Save and list photos over HTTP, then restart the App and read the same record.
See Database Connections to change the default SQLite path or configure another backend. Use transactions when several writes must succeed together.
Related Sections
- Cache covers temporary and derived values.
- File Storage covers files and objects.