예제 #1
0
func OpenMultiuserDb(directory string) *MultiuserDb {
	multiuserDb, err := sqlite.Open(path.Join(directory, "users.db"))
	Must(err)
	MustExec(multiuserDb, "CREATE TABLE IF NOT EXISTS users (username TEXT, salt TEXT, passhash BLOB)")
	MustExec(multiuserDb, "CREATE TABLE IF NOT EXISTS cookies (username TEXT, cookie TEXT)")
	MustExec(multiuserDb, "CREATE TABLE IF NOT EXISTS tokens (username TEXT, token TEXT)")
	return &MultiuserDb{multiuserDb, directory}
}
예제 #2
0
파일: backend.go 프로젝트: aarzilli/pooch
func internalTasklistOpenOrCreate(filename string) *Tasklist {
	conn, err := sqlite.Open(filename)
	Must(err)

	if !HasTable(conn, "errorlog") { // optimization, if the last added table exists exists do not try to create anything
		MustExec(conn, "CREATE TABLE IF NOT EXISTS tasks(id TEXT PRIMARY KEY, title_field TEXT, text_field TEXT, priority INTEGER, trigger_at_field DATE, sort TEXT);")
		MustExec(conn, "CREATE INDEX IF NOT EXISTS tasks_id ON tasks(id);")

		if !HasTable(conn, "ridx") { // Workaround for non-accepted CREATE VIRTUAL TABLE IF NOT EXISTS
			MustExec(conn, "CREATE VIRTUAL TABLE ridx USING fts3(id TEXT, title_field TEXT, text_field TEXT);")
		}

		MustExec(conn, "CREATE TABLE IF NOT EXISTS columns(id TEXT, name TEXT, value TEXT, FOREIGN KEY (id) REFERENCES tasks (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED)")
		MustExec(conn, "CREATE INDEX IF NOT EXISTS columns_id ON columns(id);")

		MustExec(conn, "CREATE TABLE IF NOT EXISTS saved_searches(name TEXT, value TEXT);")
	}

	MustExec(conn, "CREATE TABLE IF NOT EXISTS settings(name TEXT UNIQUE, value TEXT);")
	MustExec(conn, "INSERT OR IGNORE INTO settings(name, value) VALUES (\"timezone\", \"0\");")
	MustExec(conn, "INSERT OR IGNORE INTO settings(name, value) VALUES (\"theme\", \"tlist.css\");")
	MustExec(conn, "INSERT OR IGNORE INTO settings(name, value) VALUES (\"setup\", \"\");")
	MustExec(conn, "INSERT OR IGNORE INTO settings(name, value) VALUES (\"defaultsorttime\", \"0\");")

	MustExec(conn, "CREATE TABLE IF NOT EXISTS errorlog(timestamp TEXT, message TEXT);")

	MustExec(conn, "CREATE TABLE IF NOT EXISTS private_settings(name TEXT UNIQUE, value TEXT);")
	MustExec(conn, "INSERT OR IGNORE INTO private_settings(name, value) VALUES (\"enable_lua_execution_limit\", \"1\")")

	tasklist := &Tasklist{filename, conn, MakeLuaState(), &LuaFlags{}, &sync.Mutex{}, 1, time.Now().Unix(), true, ""}

	if tasklist.GetPrivateSetting("enable_lua_execution_limit") == "0" {
		Logf(INFO, "Tasklist '%s' runs without lua execution limits", filename)
		tasklist.executionLimitEnabled = false
	}

	tasklist.RunTimedTriggers()
	tasklist.MustExec("PRAGMA foreign_keys = ON;")
	tasklist.MustExec("PRAGMA synchronous = OFF;") // makes inserts many many times faster

	// executing setup code
	setupCode := tasklist.GetSetting("setup")
	if setupCode != "" {
		tasklist.DoString(setupCode, nil) // error is ignored, it will be logged
	}

	return tasklist
}