2021-07-13 22:25:12 +00:00
---
date: "2019-02-12:00:00+02:00"
title: "Database"
draft: false
type: "doc"
menu:
sidebar:
parent: "development"
---
# Database
2021-10-31 10:23:42 +00:00
Vikunja uses [xorm ](https://xorm.io/ ) as an abstraction layer to handle the database connection.
Please refer to [their ](https://xorm.io/docs/ ) documentation on how to exactly use it.
2021-07-13 22:25:12 +00:00
{{< 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" >}} ).
2021-10-31 10:23:42 +00:00
To learn more about how to configure your struct to create "good" tables, refer to [the xorm documentaion ](https://xorm.io/docs/ ).
2021-07-13 22:25:12 +00:00
2023-04-03 09:47:37 +00:00
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.
2021-07-13 22:25:12 +00:00
## 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.
2023-04-03 09:47:37 +00:00
**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.