
- removing spaces at end of line - fixing spelling and grammar mistakes - making sure 'Vikunja' is spelled the same way everywhere - prefer using editors word wrap instead of hardcoding word wrap in markdown (reason: different word wrap per editor & end of line space) - add newline add end where missing - remove double colon at end of headlines - remove unnecessary indention - make sure code blocks and headlines etc always have an empty line around
1.4 KiB
date, title, draft, type, menu
date | title | draft | type | menu | ||||
---|---|---|---|---|---|---|---|---|
2019-02-12:00:00+02:00 | Database | false | doc |
|
Database
Vikunja uses xorm as an abstraction layer to handle the database connection. Please refer to their documentation on how to exactly use it.
{{< table_of_contents >}}
Using the database
When using the common web handlers, you get an xorm.Session
to do database manipulations.
In other packages, use the db.NewSession()
method to get a new database session.
Adding new database tables
To add a new table to the database, create the struct and [add a migration for it]({{< ref "db-migrations.md" >}}).
To learn more about how to configure your struct to create "good" tables, refer to the xorm documentaion.
In most cases you will also need to implement the TableName() string
method on the new struct to make sure the table name matches the rest of the tables - plural.
Adding data to test fixtures
Adding data for test fixtures can be done via yaml
files in pkg/models/fixtures
.
The name of the yaml file should match the table name in the database. Adding values to it is done via array definition inside it.
Note: Table and column names need to be in snake_case as that's what is used internally in the database and for mapping values from the database to xorm so your structs can use it.