delightful-yak-60786
01/22/2024, 3:15 PMchilly-king-10285
01/22/2024, 3:15 PMchilly-king-10285
01/22/2024, 3:16 PMdsn
(Data Source Name) to a SQLite connection string. For example, if the dsn
is prefixed with sqlite://
, then SQLite will be used as the storage backend. An example configuration would look like this: DSN=sqlite:///tmp/some-db.sqlite?_fk=true
. However, using SQLite as a backend is not the same as setting dsn
to memory
. When dsn
is set to memory
, it means that data is stored in-memory. This is an ephemeral storage method, meaning all data will be removed when the service is killed. This is usually used for quick setup without worrying about setting up a database first. Here is an example of how to set the dsn
for SQLite and in-memory storage: go func GetSqlite(t testing.TB, mode sqliteMode) *DsnT { dsn := &DsnT{ MigrateUp: true, MigrateDown: false, } switch mode { case SQLiteMemory: dsn.Name = "memory" dsn.Conn = fmt.Sprintf("<sqlite://file:%s?_fk=true&cache=shared&mode=memory>", t.Name()) case SQLiteFile: t.Cleanup(func() { _ = os.Remove("TestDB.sqlite") }) fallthrough case SQLiteDebug: dsn.Name = "sqlite" dsn.Conn = "<sqlite://file:TestDB.sqlite?_fk=true>" } return dsn }
In this example, SQLiteMemory
mode sets the dsn
to an in-memory SQLite database, while SQLiteFile
and SQLiteDebug
modes set the dsn
to a SQLite file database. Sources: - [Data storage and persistence](https://www.ory.sh/docs/self-hosted/deployment#data-storage-and-persistence) - [Debugging Tests](https://www.ory.sh/docs/ecosystem/contributing#debugging-tests)delightful-yak-60786
01/22/2024, 3:18 PMchilly-king-10285
01/22/2024, 3:18 PMchilly-king-10285
01/22/2024, 3:19 PM