From 0d23ef86dec2ae8fdfc08e8b3d302eb9bedc0dd6 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Wed, 26 Aug 2020 16:13:26 +0300 Subject: [PATCH] dialect/sql: wraps the bytes.Buffer methods to make them chainable --- dialect/sql/builder.go | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/dialect/sql/builder.go b/dialect/sql/builder.go index 711964d65..47e7d755c 100644 --- a/dialect/sql/builder.go +++ b/dialect/sql/builder.go @@ -1839,16 +1839,6 @@ func (b *Builder) Quote(ident string) string { } } -// isIdent reports if the given string is a dialect identifier. -func (b *Builder) isIdent(s string) bool { - switch { - case b.postgres(): - return strings.Contains(s, `"`) - default: - return strings.Contains(s, "`") - } -} - // Ident appends the given string as an identifier. func (b *Builder) Ident(s string) *Builder { switch { @@ -1876,6 +1866,18 @@ func (b *Builder) IdentComma(s ...string) *Builder { return b } +// WriteByte wraps the Buffer.WriteByte to make it chainable with other methods. +func (b *Builder) WriteByte(c byte) *Builder { + b.Buffer.WriteByte(c) + return b +} + +// WriteString wraps the Buffer.WriteString to make it chainable with other methods. +func (b *Builder) WriteString(s string) *Builder { + b.Buffer.WriteString(s) + return b +} + // JSONOption allows for calling database JSON paths with functional options. type JSONOption func(*JSONPath) @@ -2110,6 +2112,16 @@ func (b *Builder) fromIdent(ident string) { // otherwise, use the default. } +// isIdent reports if the given string is a dialect identifier. +func (b *Builder) isIdent(s string) bool { + switch { + case b.postgres(): + return strings.Contains(s, `"`) + default: + return strings.Contains(s, "`") + } +} + // state wraps the all methods for setting and getting // update state between all queries in the query tree. type state interface {