Skip to content

Commit 46c79d0

Browse files
committed
Fix package naming of dialects & refactor dialect naming convention
1 parent f38cc16 commit 46c79d0

File tree

5 files changed

+60
-58
lines changed

5 files changed

+60
-58
lines changed

dialects/mysql/mysql.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,53 @@ import (
1313

1414
const ()
1515

16-
// MysqlDialect is a type of dialect that can be used with mysql driver
17-
type MysqlDialect struct {
16+
// Dialect is a type of dialect that can be used with mysql driver
17+
type Dialect struct {
1818
escaping bool
1919
}
2020

21-
// NewMysqlDialect returns a new MysqlDialect
22-
func NewMysqlDialect() qb.Dialect {
23-
return &MysqlDialect{false}
21+
// NewDialect returns a new MysqlDialect
22+
func NewDialect() qb.Dialect {
23+
return &Dialect{false}
2424
}
2525

2626
func init() {
27-
qb.RegisterDialect("mysql", NewMysqlDialect)
27+
qb.RegisterDialect("mysql", NewDialect)
2828
}
2929

3030
// CompileType compiles a type into its DDL
31-
func (d *MysqlDialect) CompileType(t qb.TypeElem) string {
31+
func (d *Dialect) CompileType(t qb.TypeElem) string {
3232
if t.Name == "UUID" {
3333
return "VARCHAR(36)"
3434
}
3535
return qb.DefaultCompileType(t, d.SupportsUnsigned())
3636
}
3737

3838
// Escape wraps the string with escape characters of the dialect
39-
func (d *MysqlDialect) Escape(str string) string {
39+
func (d *Dialect) Escape(str string) string {
4040
if d.escaping {
4141
return fmt.Sprintf("`%s`", str)
4242
}
4343
return str
4444
}
4545

4646
// EscapeAll wraps all elements of string array
47-
func (d *MysqlDialect) EscapeAll(strings []string) []string {
47+
func (d *Dialect) EscapeAll(strings []string) []string {
4848
return qb.EscapeAll(d, strings[0:])
4949
}
5050

5151
// SetEscaping sets the escaping parameter of dialect
52-
func (d *MysqlDialect) SetEscaping(escaping bool) {
52+
func (d *Dialect) SetEscaping(escaping bool) {
5353
d.escaping = escaping
5454
}
5555

5656
// Escaping gets the escaping parameter of dialect
57-
func (d *MysqlDialect) Escaping() bool {
57+
func (d *Dialect) Escaping() bool {
5858
return d.escaping
5959
}
6060

6161
// AutoIncrement generates auto increment sql of current dialect
62-
func (d *MysqlDialect) AutoIncrement(column *qb.ColumnElem) string {
62+
func (d *Dialect) AutoIncrement(column *qb.ColumnElem) string {
6363
colSpec := d.CompileType(column.Type)
6464
if column.Options.InlinePrimaryKey {
6565
colSpec += " PRIMARY KEY"
@@ -69,20 +69,20 @@ func (d *MysqlDialect) AutoIncrement(column *qb.ColumnElem) string {
6969
}
7070

7171
// SupportsUnsigned returns whether driver supports unsigned type mappings or not
72-
func (d *MysqlDialect) SupportsUnsigned() bool { return true }
72+
func (d *Dialect) SupportsUnsigned() bool { return true }
7373

7474
// Driver returns the current driver of dialect
75-
func (d *MysqlDialect) Driver() string {
75+
func (d *Dialect) Driver() string {
7676
return "mysql"
7777
}
7878

7979
// GetCompiler returns a MysqlCompiler
80-
func (d *MysqlDialect) GetCompiler() qb.Compiler {
80+
func (d *Dialect) GetCompiler() qb.Compiler {
8181
return MysqlCompiler{qb.NewSQLCompiler(d)}
8282
}
8383

8484
// WrapError wraps a native error in a qb Error
85-
func (d *MysqlDialect) WrapError(err error) qb.Error {
85+
func (d *Dialect) WrapError(err error) qb.Error {
8686
qbErr := qb.Error{Orig: err}
8787
mErr, ok := err.(*mysql.MySQLError)
8888
if !ok {

dialects/postgres/postgres.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package qb
1+
package postgres
22

33
import (
44
"fmt"
@@ -8,54 +8,54 @@ import (
88
"github.com/slicebit/qb"
99
)
1010

11-
// PostgresDialect is a type of dialect that can be used with postgres driver
12-
type PostgresDialect struct {
11+
// Dialect is a type of dialect that can be used with postgres driver
12+
type Dialect struct {
1313
bindingIndex int
1414
escaping bool
1515
}
1616

17-
// NewPostgresDialect returns a new PostgresDialect
18-
func NewPostgresDialect() qb.Dialect {
19-
return &PostgresDialect{escaping: false, bindingIndex: 0}
17+
// NewDialect returns a new PostgresDialect
18+
func NewDialect() qb.Dialect {
19+
return &Dialect{escaping: false, bindingIndex: 0}
2020
}
2121

2222
func init() {
23-
qb.RegisterDialect("postgres", NewPostgresDialect)
23+
qb.RegisterDialect("postgres", NewDialect)
2424
}
2525

2626
// CompileType compiles a type into its DDL
27-
func (d *PostgresDialect) CompileType(t qb.TypeElem) string {
27+
func (d *Dialect) CompileType(t qb.TypeElem) string {
2828
if t.Name == "BLOB" {
2929
return "bytea"
3030
}
3131
return qb.DefaultCompileType(t, d.SupportsUnsigned())
3232
}
3333

3434
// Escape wraps the string with escape characters of the dialect
35-
func (d *PostgresDialect) Escape(str string) string {
35+
func (d *Dialect) Escape(str string) string {
3636
if d.escaping {
3737
return fmt.Sprintf("\"%s\"", str)
3838
}
3939
return str
4040
}
4141

4242
// EscapeAll wraps all elements of string array
43-
func (d *PostgresDialect) EscapeAll(strings []string) []string {
43+
func (d *Dialect) EscapeAll(strings []string) []string {
4444
return qb.EscapeAll(d, strings[0:])
4545
}
4646

4747
// SetEscaping sets the escaping parameter of dialect
48-
func (d *PostgresDialect) SetEscaping(escaping bool) {
48+
func (d *Dialect) SetEscaping(escaping bool) {
4949
d.escaping = escaping
5050
}
5151

5252
// Escaping gets the escaping parameter of dialect
53-
func (d *PostgresDialect) Escaping() bool {
53+
func (d *Dialect) Escaping() bool {
5454
return d.escaping
5555
}
5656

5757
// AutoIncrement generates auto increment sql of current dialect
58-
func (d *PostgresDialect) AutoIncrement(column *qb.ColumnElem) string {
58+
func (d *Dialect) AutoIncrement(column *qb.ColumnElem) string {
5959
var colSpec string
6060
if column.Type.Name == "BIGINT" {
6161
colSpec = "BIGSERIAL"
@@ -71,20 +71,20 @@ func (d *PostgresDialect) AutoIncrement(column *qb.ColumnElem) string {
7171
}
7272

7373
// SupportsUnsigned returns whether driver supports unsigned type mappings or not
74-
func (d *PostgresDialect) SupportsUnsigned() bool { return false }
74+
func (d *Dialect) SupportsUnsigned() bool { return false }
7575

7676
// Driver returns the current driver of dialect
77-
func (d *PostgresDialect) Driver() string {
77+
func (d *Dialect) Driver() string {
7878
return "postgres"
7979
}
8080

8181
// GetCompiler returns a PostgresCompiler
82-
func (d *PostgresDialect) GetCompiler() qb.Compiler {
82+
func (d *Dialect) GetCompiler() qb.Compiler {
8383
return PostgresCompiler{qb.NewSQLCompiler(d)}
8484
}
8585

8686
// WrapError wraps a native error in a qb Error
87-
func (d *PostgresDialect) WrapError(err error) (qbErr qb.Error) {
87+
func (d *Dialect) WrapError(err error) (qbErr qb.Error) {
8888
qbErr.Orig = err
8989
pgErr, ok := err.(*pq.Error)
9090
if !ok {

dialects/postgres/postgres_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
package qb
1+
package postgres
22

33
import (
44
"database/sql"
55
"errors"
6+
"os"
7+
"testing"
8+
"time"
9+
610
"github.com/lib/pq"
711
"github.com/slicebit/qb"
812
"github.com/stretchr/testify/assert"
913
"github.com/stretchr/testify/suite"
10-
"os"
11-
"testing"
12-
"time"
1314
)
1415

1516
var postgresDsn = "user=postgres dbname=qb_test sslmode=disable"

dialects/sqlite/sqlite.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package qb
1+
package sqlite3
22

33
import (
44
"fmt"
@@ -8,75 +8,75 @@ import (
88
"github.com/slicebit/qb"
99
)
1010

11-
// SqliteDialect is a type of dialect that can be used with sqlite driver
12-
type SqliteDialect struct {
11+
// Dialect is a type of dialect that can be used with sqlite driver
12+
type Dialect struct {
1313
escaping bool
1414
}
1515

16-
// NewSqliteDialect instanciate a SqliteDialect
17-
func NewSqliteDialect() qb.Dialect {
18-
return &SqliteDialect{false}
16+
// NewDialect creates a new sqlite3 dialect
17+
func NewDialect() qb.Dialect {
18+
return &Dialect{false}
1919
}
2020

2121
func init() {
22-
qb.RegisterDialect("sqlite3", NewSqliteDialect)
23-
qb.RegisterDialect("sqlite", NewSqliteDialect)
22+
qb.RegisterDialect("sqlite3", NewDialect)
23+
qb.RegisterDialect("sqlite", NewDialect)
2424
}
2525

2626
// CompileType compiles a type into its DDL
27-
func (d *SqliteDialect) CompileType(t qb.TypeElem) string {
27+
func (d *Dialect) CompileType(t qb.TypeElem) string {
2828
if t.Name == "UUID" {
2929
return "VARCHAR(36)"
3030
}
3131
return qb.DefaultCompileType(t, d.SupportsUnsigned())
3232
}
3333

3434
// Escape wraps the string with escape characters of the dialect
35-
func (d *SqliteDialect) Escape(str string) string {
35+
func (d *Dialect) Escape(str string) string {
3636
if d.escaping {
3737
return fmt.Sprintf(`"%s"`, str)
3838
}
3939
return str
4040
}
4141

4242
// EscapeAll wraps all elements of string array
43-
func (d *SqliteDialect) EscapeAll(strings []string) []string {
43+
func (d *Dialect) EscapeAll(strings []string) []string {
4444
return qb.EscapeAll(d, strings[0:])
4545
}
4646

4747
// SetEscaping sets the escaping parameter of dialect
48-
func (d *SqliteDialect) SetEscaping(escaping bool) {
48+
func (d *Dialect) SetEscaping(escaping bool) {
4949
d.escaping = escaping
5050
}
5151

5252
// Escaping gets the escaping parameter of dialect
53-
func (d *SqliteDialect) Escaping() bool {
53+
func (d *Dialect) Escaping() bool {
5454
return d.escaping
5555
}
5656

5757
// AutoIncrement generates auto increment sql of current dialect
58-
func (d *SqliteDialect) AutoIncrement(column *qb.ColumnElem) string {
58+
func (d *Dialect) AutoIncrement(column *qb.ColumnElem) string {
5959
if !column.Options.InlinePrimaryKey {
6060
panic("Sqlite does not support non-primarykey autoincrement columns")
6161
}
6262
return "INTEGER PRIMARY KEY"
6363
}
6464

6565
// SupportsUnsigned returns whether driver supports unsigned type mappings or not
66-
func (d *SqliteDialect) SupportsUnsigned() bool { return false }
66+
func (d *Dialect) SupportsUnsigned() bool { return false }
6767

6868
// Driver returns the current driver of dialect
69-
func (d *SqliteDialect) Driver() string {
69+
func (d *Dialect) Driver() string {
7070
return "sqlite3"
7171
}
7272

7373
// GetCompiler returns a SqliteCompiler
74-
func (d *SqliteDialect) GetCompiler() qb.Compiler {
74+
func (d *Dialect) GetCompiler() qb.Compiler {
7575
return SqliteCompiler{qb.NewSQLCompiler(d)}
7676
}
7777

7878
// WrapError wraps a native error in a qb Error
79-
func (d *SqliteDialect) WrapError(err error) qb.Error {
79+
func (d *Dialect) WrapError(err error) qb.Error {
8080
qbErr := qb.Error{Orig: err}
8181
sErr, ok := err.(sqlite3.Error)
8282
if !ok {

dialects/sqlite/sqlite_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
package qb
1+
package sqlite3
22

33
import (
44
"database/sql"
55
"errors"
6+
"testing"
7+
"time"
8+
69
"github.com/mattn/go-sqlite3"
710
"github.com/slicebit/qb"
811
"github.com/stretchr/testify/assert"
912
"github.com/stretchr/testify/suite"
10-
"testing"
11-
"time"
1213
)
1314

1415
func asSQLBinds(clause qb.Clause, dialect qb.Dialect) (string, []interface{}) {

0 commit comments

Comments
 (0)