forked from go-gorm/gorm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
222 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package clause | ||
|
||
type Insert struct { | ||
Table Table | ||
Priority string | ||
} | ||
|
||
// Name insert clause name | ||
func (insert Insert) Name() string { | ||
return "INSERT" | ||
} | ||
|
||
// Build build insert clause | ||
func (insert Insert) Build(builder Builder) { | ||
if insert.Priority != "" { | ||
builder.Write(insert.Priority) | ||
builder.WriteByte(' ') | ||
} | ||
|
||
builder.Write("INTO ") | ||
builder.WriteQuoted(insert.Table) | ||
} | ||
|
||
// MergeExpression merge insert clauses | ||
func (insert Insert) MergeExpression(expr Expression) { | ||
if v, ok := expr.(Insert); ok { | ||
if insert.Priority == "" { | ||
insert.Priority = v.Priority | ||
} | ||
if insert.Table.Table == "" { | ||
insert.Table = v.Table | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package clause | ||
|
||
type Values struct { | ||
Columns []Column | ||
Values [][]interface{} | ||
} | ||
|
||
// Name from clause name | ||
func (Values) Name() string { | ||
return "" | ||
} | ||
|
||
// Build build from clause | ||
func (values Values) Build(builder Builder) { | ||
if len(values.Columns) > 0 { | ||
builder.WriteByte('(') | ||
for idx, column := range values.Columns { | ||
if idx > 0 { | ||
builder.WriteByte(',') | ||
} | ||
builder.WriteQuoted(column) | ||
} | ||
builder.WriteByte(')') | ||
|
||
builder.Write(" VALUES ") | ||
|
||
for idx, value := range values.Values { | ||
builder.WriteByte('(') | ||
if idx > 0 { | ||
builder.WriteByte(',') | ||
} | ||
|
||
builder.Write(builder.AddVar(value...)) | ||
builder.WriteByte(')') | ||
} | ||
} else { | ||
builder.Write("DEFAULT VALUES") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package postgres | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"github.com/jinzhu/gorm" | ||
"github.com/jinzhu/gorm/callbacks" | ||
_ "github.com/lib/pq" | ||
) | ||
|
||
type Dialector struct { | ||
DSN string | ||
} | ||
|
||
func Open(dsn string) gorm.Dialector { | ||
return &Dialector{DSN: dsn} | ||
} | ||
|
||
func (dialector Dialector) Initialize(db *gorm.DB) (err error) { | ||
// register callbacks | ||
callbacks.RegisterDefaultCallbacks(db) | ||
|
||
db.DB, err = sql.Open("postgres", dialector.DSN) | ||
return | ||
} | ||
|
||
func (Dialector) Migrator() gorm.Migrator { | ||
return nil | ||
} | ||
|
||
func (Dialector) BindVar(stmt *gorm.Statement, v interface{}) string { | ||
return "?" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,33 @@ | ||
package sqlite | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"github.com/jinzhu/gorm" | ||
"github.com/jinzhu/gorm/callbacks" | ||
_ "github.com/mattn/go-sqlite3" | ||
) | ||
|
||
type Dialector struct { | ||
DSN string | ||
} | ||
|
||
func Open(dsn string) gorm.Dialector { | ||
return &Dialector{} | ||
return &Dialector{DSN: dsn} | ||
} | ||
|
||
func (Dialector) Initialize(db *gorm.DB) error { | ||
func (dialector Dialector) Initialize(db *gorm.DB) (err error) { | ||
// register callbacks | ||
callbacks.RegisterDefaultCallbacks(db) | ||
|
||
return nil | ||
db.DB, err = sql.Open("sqlite3", dialector.DSN) | ||
return | ||
} | ||
|
||
func (Dialector) Migrator() gorm.Migrator { | ||
return nil | ||
} | ||
|
||
func (Dialector) BindVar(stmt gorm.Statement, v interface{}) string { | ||
func (Dialector) BindVar(stmt *gorm.Statement, v interface{}) string { | ||
return "?" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.