glebarez / sqlite

The pure-Go SQLite driver for GORM
MIT License
615 stars 40 forks source link

Is it possible to set a journal_mode? #27

Closed alexkmbk closed 2 years ago

glebarez commented 2 years ago

sure, see https://github.com/glebarez/go-sqlite#settings-pragmas-in-connection-string

alexkmbk commented 2 years ago

Yeah, thank you! it really works.

alexkmbk commented 2 years ago

sure, see https://github.com/glebarez/go-sqlite#settings-pragmas-in-connection-string

but if I would like to set both: shared cache and journal mode, should I use the syntax like this: "?cache=shared&_pragma=journal_mode(MEMORY)" ?

glebarez commented 2 years ago

sure, see https://github.com/glebarez/go-sqlite#settings-pragmas-in-connection-string

but if I would like to set both: shared cache and journal mode, should I use the syntax like this:

"?cache=shared&_pragma=journal_mode(MEMORY)" ?

cache option is parsed by sqlite itself. According to docs (see URI Filenames section), you must prepend your connection string with file: to enable this parsing.

So, in your case you should use it like this: "file:data.db?cache=shared&_pragma=journal_mode(MEMORY)" or "file::memory:?cache=shared&_pragma=journal_mode(MEMORY)" (for in-memory DB)

alexkmbk commented 2 years ago

sure, see https://github.com/glebarez/go-sqlite#settings-pragmas-in-connection-string

but if I would like to set both: shared cache and journal mode, should I use the syntax like this: "?cache=shared&_pragma=journal_mode(MEMORY)" ?

cache option is parsed by sqlite itself. According to docs (see URI Filenames section), you must prepend your connection string with file: to enable this parsing.

So, in your case you should use it like this: "file:data.db?cache=shared&_pragma=journal_mode(MEMORY)" or "file::memory:?cache=shared&_pragma=journal_mode(MEMORY)" (for in-memory DB)

yes, thanks!