mirror of https://github.com/fmartingr/shiori.git
Merge pull request #3 from sascha-andres/feature/db-path-config
Make path to database configurable
This commit is contained in:
commit
1338a443cd
|
@ -9,6 +9,7 @@ Shiori is a simple bookmarks manager written in Go language. Intended as a simpl
|
|||
- [Features](#features)
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [Advanced](#advanced)
|
||||
- [Examples](#examples)
|
||||
- [License](#license)
|
||||
|
||||
|
@ -57,6 +58,10 @@ Flags:
|
|||
Use "shiori [command] --help" for more information about a command.
|
||||
```
|
||||
|
||||
### Advanced
|
||||
|
||||
By default, `shiori` will create database in the location where you run it. For example, if you run `shiori`. To set the database to a specific location, you can set the environment variable `ENV_SHIORI_DB` to your desired path.
|
||||
|
||||
## Examples
|
||||
|
||||
1. Save new bookmark with tags "nature" and "climate-change".
|
||||
|
|
|
@ -19,10 +19,10 @@ type SQLiteDatabase struct {
|
|||
}
|
||||
|
||||
// OpenSQLiteDatabase creates and open connection to new SQLite3 database.
|
||||
func OpenSQLiteDatabase() (*SQLiteDatabase, error) {
|
||||
func OpenSQLiteDatabase(databasePath string) (*SQLiteDatabase, error) {
|
||||
// Open database and start transaction
|
||||
var err error
|
||||
db := sqlx.MustConnect("sqlite3", "shiori.db")
|
||||
db := sqlx.MustConnect("sqlite3", databasePath)
|
||||
tx := db.MustBegin()
|
||||
|
||||
// Make sure to rollback if panic ever happened
|
||||
|
|
9
main.go
9
main.go
|
@ -2,13 +2,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/RadhiFadlillah/shiori/cmd"
|
||||
db "github.com/RadhiFadlillah/shiori/database"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
sqliteDB, err := db.OpenSQLiteDatabase()
|
||||
databasePath := "shiori.db"
|
||||
if value, found := os.LookupEnv("ENV_SHIORI_DB"); found {
|
||||
databasePath = value
|
||||
}
|
||||
|
||||
sqliteDB, err := db.OpenSQLiteDatabase(databasePath)
|
||||
checkError(err)
|
||||
|
||||
cmd.DB = sqliteDB
|
||||
|
|
Loading…
Reference in New Issue