feat:multi cluster application

This commit is contained in:
pengcong06
2020-05-25 22:38:03 +08:00
parent d4b7d88b4b
commit 59839439d5
73 changed files with 9838 additions and 6278 deletions

View File

@@ -2,9 +2,9 @@
# Use of this source code is governed by a Apache license
# that can be found in the LICENSE file.
FROM dhoer/flyway:5.1.4-mysql-8.0.11-alpine
FROM openpitrix/flyway:alpine
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
USER root
RUN apk add --no-cache mysql-client
COPY ./schema /flyway/sql

View File

@@ -61,9 +61,11 @@ func FromContext(ctx context.Context) (*Database, bool) {
func (db *Database) New(ctx context.Context) *Conn {
actualDb, ok := FromContext(ctx)
conn := db.Conn
if ok {
var conn *dbr.Connection
if ok || db == nil {
conn = actualDb.Conn
} else {
conn = db.Conn
}
return &Conn{
Session: conn.NewSession(&EventReceiver{ctx}),

View File

@@ -4,7 +4,6 @@ import (
"context"
"database/sql"
"fmt"
"strings"
_ "github.com/go-sql-driver/mysql"
"github.com/gocraft/dbr"
@@ -91,6 +90,14 @@ func (b *SelectQuery) Join(table, on interface{}) *SelectQuery {
b.SelectBuilder.Join(table, on)
return b
}
func (b *SelectQuery) RightJoin(table, on interface{}) *SelectQuery {
b.SelectBuilder.RightJoin(table, on)
return b
}
func (b *SelectQuery) LeftJoin(table, on interface{}) *SelectQuery {
b.SelectBuilder.LeftJoin(table, on)
return b
}
func (b *SelectQuery) JoinAs(table string, alias string, on interface{}) *SelectQuery {
b.SelectBuilder.Join(dbr.I(table).As(alias), on)
@@ -143,13 +150,12 @@ func (b *SelectQuery) LoadOne(value interface{}) error {
}
func getColumns(dbrColumns []interface{}) string {
var columns []string
for _, column := range dbrColumns {
if c, ok := column.(string); ok {
columns = append(columns, c)
return c
}
}
return strings.Join(columns, ", ")
return "*"
}
func (b *SelectQuery) Count() (count uint32, err error) {