當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.GetTx方法代碼示例

本文整理匯總了Golang中github.com/waterlink/rebecca/context.Context.GetTx方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.GetTx方法的具體用法?Golang Context.GetTx怎麽用?Golang Context.GetTx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/waterlink/rebecca/context.Context的用法示例。


在下文中一共展示了Context.GetTx方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: All

// All is for fetching all records
func (d *Driver) All(tablename string, fields []field.Field, ctx context.Context) ([][]field.Field, error) {
	if tx := ctx.GetTx(); tx != nil {
		return tx.(*Driver).All(tablename, fields, ctx.SetTx(nil))
	}

	return d.getTable(tablename), nil
}
開發者ID:waterlink,項目名稱:rebecca,代碼行數:8,代碼來源:fake.go

示例2: Where

// Where is for fetching specific records
func (d *Driver) Where(tablename string, fields []field.Field, ctx context.Context, where string, args ...interface{}) ([][]field.Field, error) {
	if tx := ctx.GetTx(); tx != nil {
		return tx.(*Driver).Where(tablename, fields, ctx.SetTx(nil), where, args...)
	}

	result := [][]field.Field{}

	fn, ok := d.whereRegistry[where]
	if !ok {
		return nil, fmt.Errorf(
			"Fake driver has no '%s' where query registerd, please register with RegisterWhere",
			where,
		)
	}

	for _, record := range d.getTable(tablename) {
		ok, err := fn(record, args...)
		if err != nil {
			return nil, fmt.Errorf("Registered query '%s' returned error - %s", where, err)
		}

		if ok {
			result = append(result, record)
		}
	}

	return result, nil
}
開發者ID:waterlink,項目名稱:rebecca,代碼行數:29,代碼來源:fake.go

示例3: All

// All is for fetching all records in current context
func (d *Driver) All(tablename string, fields []field.Field, ctx context.Context) ([][]field.Field, error) {
	names := fieldNames(fields)

	query := "SELECT %s FROM %s %s"
	query = fmt.Sprintf(query, namesRepr(names), tablename, contextFor(ctx))

	return d.readRows(ctx.GetTx(), fields, query)
}
開發者ID:waterlink,項目名稱:rebecca,代碼行數:9,代碼來源:pg.go

示例4: First

// First is for fetching only first specific record from current context matching given where query and arguments
func (d *Driver) First(tablename string, fields []field.Field, ctx context.Context, where string, args ...interface{}) ([]field.Field, error) {
	firstCtx := ctx.SetLimit(1)
	names := fieldNames(fields)

	query := "SELECT %s FROM %s WHERE %s %s"
	query = fmt.Sprintf(query, namesRepr(names), tablename, where, contextFor(firstCtx))
	return d.readRow(ctx.GetTx(), fields, query, args...)
}
開發者ID:waterlink,項目名稱:rebecca,代碼行數:9,代碼來源:pg.go

示例5: First

// First is for fetching first specific record
func (d *Driver) First(tablename string, fields []field.Field, ctx context.Context, where string, args ...interface{}) ([]field.Field, error) {
	if tx := ctx.GetTx(); tx != nil {
		return tx.(*Driver).First(tablename, fields, ctx.SetTx(nil), where, args...)
	}

	records, err := d.Where(tablename, fields, ctx, where, args...)
	if err != nil {
		return nil, fmt.Errorf("Unable to get first record - %s", err)
	}

	if len(records) == 0 {
		return nil, fmt.Errorf("Record not found with where query '%s'", where)
	}

	return records[0], nil
}
開發者ID:waterlink,項目名稱:rebecca,代碼行數:17,代碼來源:fake.go


注:本文中的github.com/waterlink/rebecca/context.Context.GetTx方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。