Пример #1
0
// SqlRepository returns a new sqlRepository or panics if it cannot
func SqlRepository() UserRepository {
	settings := settings.NewSettings("settings.json")
	db, err := sqlx.Connect(settings.DriverName(), settings.DataSource())
	if err != nil {
		panic("Error connecting to db: " + err.Error())
	}

	repo := &sqlRepository{
		db: db,
	}

	datetime := "datetime"
	if settings.DriverName() == "postgres" {
		datetime = "timestamp with time zone"
	}

	schema := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS authuser (
		key text not null primary key,
		name text,
		email text,
		password text,
		created %s,
		modified %s,
		lastactive %s
	);`, datetime, datetime, datetime)

	_, err = repo.db.Exec(schema)
	return repo
}
Пример #2
0
// SqlRepository returns a new sqlRepository or panics if it cannot
func SqlRepository() TokenRepository {
	settings := settings.NewSettings("settings.json")
	db, err := sqlx.Connect(settings.DriverName(), settings.DataSource())
	if err != nil {
		panic("Error connecting to db: " + err.Error())
	}

	repo := &sqlRepository{
		db: db,
	}

	datetime := "datetime"
	if settings.DriverName() == "postgres" {
		datetime = "timestamp with time zone"
	}

	schema := fmt.Springf(`CREATE TABLE IF NOT EXISTS token (
		token text not null primary key,
		platform text NULL,
		user text NULL,
		created %s,
		modified %s
	);`, datetime, datetime)

	_, err = repo.db.Exec(schema)
	return repo
}