Add SQLite support

This commit is contained in:
2017-11-07 00:12:06 +01:00
parent 0a108739d4
commit badcad8d70
10 changed files with 67 additions and 33 deletions
+1
View File
@@ -6,6 +6,7 @@ import (
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
uuid "github.com/satori/go.uuid"
"github.com/localhots/cmdui/backend/config"
+3 -10
View File
@@ -127,16 +127,9 @@ func (r *Job) Create() error {
r.State = string(JobStateCreated)
_, err := db.NamedExec(`
INSERT INTO jobs
SET
id = :id,
command = :command,
args = :args,
flags = :flags,
user_id = :user_id,
state = :state,
created_at = :created_at
`, r)
INSERT INTO jobs (id, command, args, flags, user_id, state, created_at)
VALUES (:id, :command, :args, :flags, :user_id, :state, :created_at)
`, r)
if err != nil {
return errors.Annotate(err, "Failed to create a job")
}
+3 -7
View File
@@ -42,13 +42,9 @@ func FindSession(id string) (*Session, error) {
func (s Session) Create() error {
_, err := db.NamedExec(`
INSERT INTO sessions
SET
id = :id,
user_id = :user_id,
created_at = :created_at,
expires_at = :expires_at
`, s)
INSERT INTO sessions (id, user_id, created_at, expires_at)
VALUES (:id, :user_id, :created_at, :expires_at)
`, s)
if err != nil {
return errors.Annotate(err, "Failed to create a session")
}
+2 -7
View File
@@ -71,13 +71,8 @@ func findUser(query string, args ...interface{}) (*User, error) {
func (u User) Create() error {
_, err := db.NamedExec(`
INSERT INTO users
SET
id = :id,
github_id = :github_id,
github_login = :github_login,
github_name = :github_name,
github_picture = :github_picture
INSERT INTO users (id, github_id, github_login, github_name, github_picture)
VALUES (:id, :github_id, :github_login, :github_name, :github_picture)
`, u)
if err != nil {
return errors.Annotate(err, "Failed to create a user")