Example #1
1
func GetIdentity(q sqlx.Queryer, id int64) (*Identity, error) {
	const (
		Q = `SELECT * FROM identities WHERE id = $1 LIMIT 1;`
	)

	identity := &Identity{}
	err := sqlx.Get(q, identity, Q, id)
	if err == sql.ErrNoRows {
		return nil, nil
	}
	if err != nil {
		return nil, err
	}

	return identity, nil
}
Example #2
1
File: db.go Project: hobeone/rss2go
func (d *Handle) unsafeGetUserByEmail(email string) (*User, error) {
	u := &User{}
	err := sqlx.Get(d.queryer, u, "SELECT * FROM user WHERE email = ?", email)
	return u, err
}
Example #3
0
File: db.go Project: hobeone/rss2go
// GetUser returns the user with the given name from the database.
func (d *Handle) GetUser(name string) (*User, error) {
	d.syncMutex.Lock()
	defer d.syncMutex.Unlock()
	u := &User{}
	err := sqlx.Get(d.queryer, u, "SELECT * FROM user WHERE name = ?", name)
	return u, err
}
Example #4
0
func (db *ChannelDBReader) GetByURL(url string) (*models.Channel, error) {
	q := `SELECT c.id, c.title, c.description, c.url, c.image, c.website
FROM channels c
WHERE url=$1`
	channel := &models.Channel{}
	return channel, dbErr(sqlx.Get(db, channel, q, url), q)
}
Example #5
0
File: db.go Project: hobeone/rss2go
// GetFeedItemByGUID returns a FeedItem for the given FeedInfo.Id and guid.
func (d *Handle) GetFeedItemByGUID(feedID int64, guid string) (*FeedItem, error) {
	fi := FeedItem{}
	d.syncMutex.Lock()
	defer d.syncMutex.Unlock()
	err := sqlx.Get(d.queryer, &fi, "SELECT * FROM feed_item WHERE feed_info_id = ? AND guid = ?", feedID, guid)
	return &fi, err
}
Example #6
0
func (db *ChannelDBReader) GetByID(id int64) (*models.Channel, error) {
	q := `SELECT c.id, c.title, c.description, c.url, c.image, c.website
FROM channels c
WHERE id=$1`
	channel := &models.Channel{}
	return channel, dbErr(sqlx.Get(db, channel, q, id), q)
}
Example #7
0
File: db.go Project: hobeone/rss2go
// GetUserByID returns the user with the given id from the database.
func (d *Handle) GetUserByID(id int64) (*User, error) {
	d.syncMutex.Lock()
	defer d.syncMutex.Unlock()
	u := &User{}
	err := sqlx.Get(d.queryer, u, "SELECT * FROM user WHERE id = ?", id)
	return u, err
}
Example #8
0
File: db.go Project: hobeone/rss2go
// GetFeedByID returns the FeedInfo for the given id.
func (d *Handle) GetFeedByID(id int64) (*FeedInfo, error) {
	d.syncMutex.Lock()
	defer d.syncMutex.Unlock()
	var f FeedInfo
	//	err := sqlx.Get(d.queryer, &f, "SELECT * from feed_info WHERE id = ? LIMIT 1", id)
	err := sqlx.Get(d.queryer, &f, "SELECT * from feed_info WHERE id = ? LIMIT 1", id)
	return &f, err
}
Example #9
0
func (balancer *Balancer) Get(result interface{}, query string, args ...interface{}) error {
	q, e := balancer.db()
	if e != nil {
		return e
	}

	return sqlx.Get(q, result, query, args...)
}
Example #10
0
func GetGalleryByID(db sqlx.Ext, id int32) (*Gallery, error) {
	q := `SELECT * FROM galleries WHERE id=$1`

	res := Gallery{}
	err := sqlx.Get(db, &res, q, id)

	return &res, tracederror.New(err)
}
Example #11
0
func (db *PodcastDBReader) GetByID(id int64) (*models.Podcast, error) {
	q := `SELECT p.id, p.title, p.enclosure_url, p.description,
    p.channel_id, c.title AS name, 
    c.image, p.pub_date, p.source
FROM podcasts p
JOIN channels c ON c.id = p.channel_id
WHERE p.id=$1`
	podcast := &models.Podcast{}
	err := sqlx.Get(db, podcast, q, id)
	return podcast, dbErr(err, q)
}
Example #12
0
func GetBlogPostByID(db sqlx.Ext, id int32) (*BlogPost, error) {
	q := `
		SELECT p.*, c.category AS category_value 
		FROM blog_posts p JOIN blog_categories c ON c.id = p.category
		WHERE p.id = $1
	`

	res := BlogPost{}
	err := sqlx.Get(db, &res, q, id)
	return &res, tracederror.New(err)
}
Example #13
0
func CreateAuthorization(q sqlx.Queryer, authorization *Authorization) error {
	const (
		Q = `INSERT INTO authorizations (identity_id, application_id, code, expires_in, state, scope, redirect_uri) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING *;`
	)

	return sqlx.Get(q, authorization, Q,
		authorization.IdentityId,
		authorization.ApplicationId,
		authorization.Code,
		authorization.ExpiresIn,
		authorization.State,
		authorization.Scope,
		authorization.RedirectURI,
	)
}
Example #14
0
func GetApplicationWithClientId(q sqlx.Queryer, client_id string) (*Application, error) {
	const (
		Q = `SELECT * FROM applications WHERE client_id = $1 LIMIT 1;`
	)

	application := &Application{}
	err := sqlx.Get(q, application, Q, client_id)
	if err == sql.ErrNoRows {
		return nil, nil
	}
	if err != nil {
		return nil, err
	}

	return application, nil
}
Example #15
0
func GetAuthorizationWithCode(q sqlx.Queryer, code string) (*Authorization, error) {
	const (
		Q = `SELECT * FROM authorizations WHERE code = $1 LIMIT 1;`
	)

	authorization := &Authorization{}
	err := sqlx.Get(q, authorization, Q, code)
	if err == sql.ErrNoRows {
		return nil, nil
	}
	if err != nil {
		return nil, err
	}

	return authorization, nil
}
Example #16
0
func GetAccessTokenWithRefreshToken(q sqlx.Queryer, token string) (*AccessToken, error) {
	const (
		Q = `SELECT * FROM access_tokens WHERE refresh_token = $1 LIMIT 1;`
	)

	access_token := &AccessToken{}
	err := sqlx.Get(q, access_token, Q, token)
	if err == sql.ErrNoRows {
		return nil, nil
	}
	if err != nil {
		return nil, err
	}

	return access_token, nil
}
Example #17
0
func CreateAccessToken(q sqlx.Queryer, access_token *AccessToken) error {
	const (
		Q = `INSERT INTO access_tokens (identity_id, application_id, access_token, refresh_token, expires_in, scope, redirect_uri) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING *;`
	)

	if access_token.RefreshToken.String != "" {
		access_token.RefreshToken.Valid = true
	}

	return sqlx.Get(q, access_token, Q,
		access_token.IdentityId,
		access_token.ApplicationId,
		access_token.AccessToken,
		access_token.RefreshToken,
		access_token.ExpiresIn,
		access_token.Scope,
		access_token.RedirectURI,
	)
}
Example #18
0
func (db *UserDBReader) GetByID(id int64) (*models.User, error) {
	q := "SELECT * FROM users WHERE id=$1"
	user := &models.User{}
	err := sqlx.Get(db, user, q, id)
	return user, dbErr(err, q)
}
Example #19
0
func (db *UserDBReader) GetByNameOrEmail(identifier string) (*models.User, error) {
	q := "SELECT * FROM users WHERE email=$1 or name=$1"
	user := &models.User{}
	err := sqlx.Get(db, user, q, identifier)
	return user, dbErr(err, q)
}
Example #20
0
File: db.go Project: hobeone/rss2go
func (d *Handle) unsafeGetFeedByURL(url string) (*FeedInfo, error) {
	feed := &FeedInfo{}
	err := sqlx.Get(d.queryer, feed, `SELECT * FROM feed_info WHERE url = ? LIMIT 1`, url)
	return feed, err
}