Merge pull request #3 from sascha-andres/feature/db-path-config

Make path to database configurable
This commit is contained in:
Radhi 2018-03-05 07:21:54 +07:00 committed by GitHub
commit 1338a443cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View File

@ -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".

View File

@ -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

View File

@ -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