~samwhited/communique-tui

243e480b717a7a47dbbe410a076262196265a23e — Sam Whited a month ago 50d122b
all: create one DB per account

Signed-off-by: Sam Whited <sam@samwhited.com>
2 files changed, 9 insertions(+), 5 deletions(-)

M internal/storage/db.go
M main.go
M internal/storage/db.go => internal/storage/db.go +4 -4
@@ 42,13 42,13 @@ type DB struct {
// If dbFile is empty a fallback sequence of names is used starting with
// $XDG_DATA_HOME, then falling back to $HOME/.local/share, then falling back to
// the current working directory.
func OpenDB(ctx context.Context, appName, dbFile, schema string, debug *log.Logger) (*DB, error) {
func OpenDB(ctx context.Context, appName, account, dbFile, schema string, debug *log.Logger) (*DB, error) {
	const (
		dbDriver   = "sqlite"
		dbFileName = "db"
		dbDriver = "sqlite"
	)
	var fPath string
	var paths []string
	dbFileName := account + ".db"

	if dbFile != "" {
		paths = []string{dbFile}


@@ 67,7 67,7 @@ func OpenDB(ctx context.Context, appName, dbFile, schema string, debug *log.Logg
		if err != nil {
			debug.Printf("error getting current working directory: %v", err)
		} else {
			paths = append(paths, filepath.Join(fPath, appName+".db"))
			paths = append(paths, filepath.Join(fPath, dbFileName))
		}
	}


M main.go => main.go +5 -1
@@ 124,7 124,11 @@ Try running '%s -config' to generate a default config file.`, err, os.Args[0])
	// Open the database
	dbCtx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
	defer cancel()
	db, err := storage.OpenDB(dbCtx, appName, cfg.DB, schema, debug)
	account, err := jid.Parse(cfg.JID)
	if err != nil {
		logger.Fatalf("error parsing main account as XMPP address: %v", err)
	}
	db, err := storage.OpenDB(dbCtx, appName, account.Bare().String(), cfg.DB, schema, debug)
	if err != nil {
		logger.Fatalf("error opening database: %v", err)
	}