Exemple #1
0
func (p *builder) SqlSaveJson(id GUID, data T) (sa *db.SqlArgs) {
	buf, _ := json.Marshal(data)
	_id, _json := p.mapper("Id"), p.mapper("Json")
	sql := fmt.Sprintf(`Insert into %s(%s,%s) values($1,$2) ON CONFLICT (%s) DO UPDATE SET (%s,%s)=($1,$2)`,
		p.mapper(p.from), _id, _json, _id, _id, _json)

	return db.NewAgrs(sql, id, buf)
}
Exemple #2
0
func (p *builder) SqlSelect() (sa *db.SqlArgs) {
	sql := `SELECT ` + p.buildFields() + " FROM " + p.mapper(p.from)
	sa = db.NewAgrs(sql)
	sa = sa.Append2(p.whereArgs)
	if p.hasOrder() {
		orders := " ORDER BY " + strings.Join(p.orders, ",")
		sa = sa.Append(orders)
	}
	return sa.Append2(p.limitArgs)
}
Exemple #3
0
func (p *builder) SqlCount() (sa *db.SqlArgs) {
	sql := `SELECT count(` + p.mapper("Id") + ") FROM " + p.mapper(p.from)
	sa = db.NewAgrs(sql)
	return sa.Append2(p.whereArgs)
}
Exemple #4
0
func (p *builder) SqlDel() (sa *db.SqlArgs) {
	sql := `DELETE FROM ` + p.mapper(p.from)
	sa = db.NewAgrs(sql)
	return sa.Append2(p.whereArgs)
}
Exemple #5
0
func (p *builder) Limit(n, offset int) Ibuilder {
	p.limitArgs = db.NewAgrs(` LIMIT ? OFFSET ?`, n, offset)
	return p
}
Exemple #6
0
func (p *builder) initWhereArgs() *db.SqlArgs {
	if p.whereArgs == nil {
		p.whereArgs = db.NewAgrs(" WHERE ")
	}
	return p.whereArgs
}
Exemple #7
0
func (p *mssqlBuilder) Limit(n, offset int) Ibuilder {
	p.limitArgs = db.NewAgrs(` OFFSET ? ROW FETCH NEXT ? ROWS only`, offset, n)
	return p
}
Exemple #8
0
func (p *TxScope) Exec(query string, args ...interface{}) {
	p.exec(*db.NewAgrs(query, args...))
}