本文整理汇总了Golang中github.com/jmoiron/sqlx.Tx.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Tx.Get方法的具体用法?Golang Tx.Get怎么用?Golang Tx.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jmoiron/sqlx.Tx
的用法示例。
在下文中一共展示了Tx.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetOwnerInfos
// GetOwnerInfos get all informations about the owner of the database
func (d *Database) GetOwnerInfos(tx *sqlx.Tx) (owner DatabaseAuthor, err error) {
err = tx.Get(owner, "SELECT * FROM \"user\" u LEFT JOIN \"database\" d ON u.id = d.owner WHERE d.id = $1", d.Id)
if err != nil {
err = errors.New("database::GetOwnerInfos: " + err.Error())
}
return
}
示例2: get
func (b *Base) get(tx *sqlx.Tx, dest interface{}, query string, args ...interface{}) error {
if tx != nil {
return tx.Get(dest, query, args...)
}
return b.db.Get(dest, query, args...)
}
示例3: getDBMediaPlayerTx
func getDBMediaPlayerTx(tx *sqlx.Tx, id int64, baseComp Component, exFlags ExpansionFlags) (dbMediaPlayer, error) {
var dbMP dbMediaPlayer
// build a select statement based on the expand keys
stmt := "SELECT * FROM component c JOIN media_player_state mpstate ON c.id=mpstate.id"
if exFlags&(ExpandAll|ExpandSpecs) != 0 {
stmt += " JOIN media_player_spec mpspec ON mpspec.make=c.make AND mpspec.model=c.model"
}
// TODO: Add stats
// if exFlags&(ExpandAll|exFlags&ExpandStats) != 0 {
// stmt += " JOIN media_player_stats lstats ON c.id=lstats.id"
// }
stmt += " WHERE c.id=? LIMIT 1"
Log.Debug("getting media player", "query", stmt, "id", id)
if err := tx.Get(&dbMP, stmt, id); err != nil {
return dbMediaPlayer{}, fmt.Errorf("error getting media player with id %v: %v", id, err)
}
if dbMP.ID == 0 {
Log.Warn("media player has id 0", "search_id", id)
return dbMediaPlayer{}, fmt.Errorf("got unexpected component id: 0")
}
return dbMP, nil
}
示例4: CreateIdentity
func CreateIdentity(tx *sqlx.Tx, identity *Identity) error {
const (
Q = `INSERT INTO identities DEFAULT VALUES RETURNING *;`
)
return tx.Get(identity, Q)
}
示例5: GetLastImport
// GetLastImport lists last import informations
func (d *Database) GetLastImport(tx *sqlx.Tx) (imp Import, err error) {
imp = Import{}
err = tx.Get(&imp, "SELECT * FROM import WHERE i.jdatabase_id = $1 ORDER by id DESC LIMIT 1", d.Id)
if err != nil {
err = errors.New("database::GetLastImport: " + err.Error())
}
return
}
示例6: GetProjectId
// GetProjectId get the project of the user
func (u *User) GetProjectId(tx *sqlx.Tx) (projectID int, err error) {
err = tx.Get(&projectID, "SELECT id FROM project WHERE user_id = $1", u.Id)
if err == sql.ErrNoRows {
err = nil
projectID = 0
}
return
}
示例7: getBaseComponentTx
func getBaseComponentTx(tx *sqlx.Tx, deviceID types.DeviceID, compName string) (Component, bool) {
var dbComp Component
err := tx.Get(&dbComp, "SELECT * FROM component WHERE device_id=? AND name=? LIMIT 1", deviceID, compName)
if err != nil || dbComp.ID == 0 {
return dbComp, false
}
return dbComp, true
}
示例8: GetBuildIDFromDBTx
// GetBuildIDFromDBTx retrieves the ID for the given build from the database
// as specified by the given master, builder, and build number.
func GetBuildIDFromDBTx(builder, master string, buildNumber int, tx *sqlx.Tx) (int, error) {
var id int
stmt := fmt.Sprintf("SELECT id FROM %s WHERE builder = ? AND master = ? AND number = ?", TABLE_BUILDS)
if err := tx.Get(&id, stmt, builder, master, buildNumber); err != nil {
return -1, fmt.Errorf("Unable to retrieve build ID from database: %v", err)
}
return id, nil
}
示例9: getDBDeviceTx
func getDBDeviceTx(tx *sqlx.Tx, extID types.ExternalDeviceID) (Device, bool) {
var dev Device
err := tx.Get(&dev, "SELECT * FROM device WHERE manufacturer=? AND external_id=? LIMIT 1", extID.Manufacturer, extID.ID)
if err != nil || dev.ID == 0 {
Log.Debug("could not get dbDevice", "err", err, "ext_id", extID, "dbDev_id", dev.ID)
return dev, false
}
return dev, true
}
示例10: IsLinkedToProject
// IsLinkedToProject returns true or false if database is linked or not to user project
func (d *Database) IsLinkedToProject(tx *sqlx.Tx, project_ID int) (linked bool, err error) {
linked = false
c := 0
err = tx.Get(&c, "SELECT count(*) FROM project__database WHERE project_id = $1 AND database_id = $2", project_ID, d.Id)
if c > 0 {
linked = true
}
return
}
示例11: artifactsFindByRepoSha
// artifactsFindByRepoSha finds an artifact by image.
func artifactsFindByRepoSha(tx *sqlx.Tx, repoSha string) (*Artifact, error) {
parts := strings.Split(repoSha, "@")
var sql = `SELECT * FROM artifacts
WHERE repository = ?
AND sha = ?
ORDER BY seq desc
LIMIT 1`
var a Artifact
err := tx.Get(&a, tx.Rebind(sql), parts[0], parts[1])
return &a, err
}
示例12: findConsumer
func findConsumer(id int, db *sqlx.Tx) *Consumer {
consumer := &Consumer{}
consumer._db = db
db.Get(consumer, "SELECT `id`, `name`, `created_at`, `updated_at`, `created_by`, `updated_by`, `enabled`, `deleted`, `info_token` FROM `consumer` WHERE `id` = ?", id)
if consumer.Id == 0 {
return nil
}
return consumer
}
示例13: buildsFindByRepoSha
// buildsFindByRepoSha finds a build by repository and sha.
func buildsFindByRepoSha(tx *sqlx.Tx, repoSha string) (*Build, error) {
parts := strings.Split(repoSha, "@")
var sql = `SELECT * FROM builds
WHERE repository = ?
AND sha = ?
ORDER BY seq desc
LIMIT 1`
var b Build
err := tx.Get(&b, tx.Rebind(sql), parts[0], parts[1])
return &b, err
}
示例14: GetLastHandle
// GetHandles get last handle linked to a database
func (d *Database) GetLastHandle(tx *sqlx.Tx) (handle *Database_handle, err error) {
handle = &Database_handle{}
err = tx.Get(handle, "SELECT * FROM database_handle WHERE database_id = $1 ORDER BY id DESC LIMIT 1", d.Id)
switch {
case err == sql.ErrNoRows:
return handle, nil
case err != nil:
return
}
return
}
示例15: getBaseComponentByIDTx
func getBaseComponentByIDTx(tx *sqlx.Tx, id int64) (Component, error) {
var dbComp Component
if err := tx.Get(&dbComp, "SELECT * FROM component WHERE id=? LIMIT 1", id); err != nil {
Log.Debug("could not get base component", "id", id, "err", err)
return Component{}, fmt.Errorf("error getting component with id %v: %v", id, err)
}
if dbComp.ID == 0 {
Log.Warn("base component has id 0", "search_id", id)
return Component{}, fmt.Errorf("got unexpected component id: 0")
}
Log.Debug("got base component", "id", id, "comp", dbComp)
return dbComp, nil
}