github.com/acoshift/pgsql@v0.15.3/pgstmt/group.go (about)

     1  package pgstmt
     2  
     3  type group struct {
     4  	q   []any
     5  	sep string
     6  }
     7  
     8  func (b *group) getSep() string {
     9  	if b.sep == "" {
    10  		return ", "
    11  	}
    12  	return b.sep
    13  }
    14  
    15  func (b *group) empty() bool {
    16  	return len(b.q) == 0
    17  }
    18  
    19  func (b *group) push(q ...any) {
    20  	b.q = append(b.q, q...)
    21  }
    22  
    23  func (b *group) pushString(q ...string) {
    24  	for _, x := range q {
    25  		b.q = append(b.q, x)
    26  	}
    27  }
    28  
    29  func withGroup(sep string, q ...any) any {
    30  	var g group
    31  	g.sep = sep
    32  	g.push(q...)
    33  	return &g
    34  }
    35  
    36  type parenGroup struct {
    37  	group
    38  	prefix string
    39  }
    40  
    41  func paren(q ...any) any {
    42  	var p parenGroup
    43  	p.push(q...)
    44  	return &p
    45  }
    46  
    47  func parenString(q ...string) any {
    48  	var p parenGroup
    49  	p.pushString(q...)
    50  	return &p
    51  }
    52  
    53  func withParen(sep string, q ...any) any {
    54  	var p parenGroup
    55  	p.sep = sep
    56  	p.push(q...)
    57  	return &p
    58  }