2016-08-18 07:26:24 +02:00
|
|
|
package drivers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/vattle/sqlboiler/bdb"
|
|
|
|
"github.com/vattle/sqlboiler/strmangle"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MockDriver is a mock implementation of the bdb driver Interface
|
2016-08-18 14:11:02 +02:00
|
|
|
type MockDriver struct{}
|
2016-08-18 07:26:24 +02:00
|
|
|
|
|
|
|
// TableNames returns a list of mock table names
|
2016-09-09 07:41:57 +02:00
|
|
|
func (m *MockDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error) {
|
2016-09-05 16:41:12 +02:00
|
|
|
if len(whitelist) > 0 {
|
|
|
|
return whitelist, nil
|
|
|
|
}
|
2016-08-23 05:38:43 +02:00
|
|
|
tables := []string{"pilots", "jets", "airports", "licenses", "hangars", "languages", "pilot_languages"}
|
2016-09-09 07:41:57 +02:00
|
|
|
return strmangle.SetComplement(tables, blacklist), nil
|
2016-08-18 07:26:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Columns returns a list of mock columns
|
2016-09-08 23:23:10 +02:00
|
|
|
func (m *MockDriver) Columns(schema, tableName string) ([]bdb.Column, error) {
|
2016-08-18 07:26:24 +02:00
|
|
|
return map[string][]bdb.Column{
|
2016-08-23 05:38:43 +02:00
|
|
|
"pilots": {
|
|
|
|
{Name: "id", Type: "int", DBType: "integer"},
|
|
|
|
{Name: "name", Type: "string", DBType: "character"},
|
|
|
|
},
|
2016-08-18 14:11:02 +02:00
|
|
|
"airports": {
|
|
|
|
{Name: "id", Type: "int", DBType: "integer"},
|
|
|
|
{Name: "size", Type: "null.Int", DBType: "integer", Nullable: true},
|
|
|
|
},
|
2016-08-18 07:26:24 +02:00
|
|
|
"jets": {
|
2016-08-18 14:11:02 +02:00
|
|
|
{Name: "id", Type: "int", DBType: "integer"},
|
|
|
|
{Name: "pilot_id", Type: "int", DBType: "integer", Nullable: true, Unique: true},
|
|
|
|
{Name: "airport_id", Type: "int", DBType: "integer"},
|
|
|
|
{Name: "name", Type: "string", DBType: "character", Nullable: false},
|
|
|
|
{Name: "color", Type: "null.String", DBType: "character", Nullable: true},
|
|
|
|
{Name: "uuid", Type: "string", DBType: "uuid", Nullable: true},
|
|
|
|
{Name: "identifier", Type: "string", DBType: "uuid", Nullable: false},
|
|
|
|
{Name: "cargo", Type: "[]byte", DBType: "bytea", Nullable: false},
|
|
|
|
{Name: "manifest", Type: "[]byte", DBType: "bytea", Nullable: true, Unique: true},
|
2016-08-18 07:26:24 +02:00
|
|
|
},
|
|
|
|
"licenses": {
|
2016-08-18 14:11:02 +02:00
|
|
|
{Name: "id", Type: "int", DBType: "integer"},
|
|
|
|
{Name: "pilot_id", Type: "int", DBType: "integer"},
|
|
|
|
},
|
|
|
|
"hangars": {
|
|
|
|
{Name: "id", Type: "int", DBType: "integer"},
|
|
|
|
{Name: "name", Type: "string", DBType: "character", Nullable: true, Unique: true},
|
2016-08-18 07:26:24 +02:00
|
|
|
},
|
2016-08-23 05:38:43 +02:00
|
|
|
"languages": {
|
|
|
|
{Name: "id", Type: "int", DBType: "integer"},
|
|
|
|
{Name: "language", Type: "string", DBType: "character", Nullable: false, Unique: true},
|
|
|
|
},
|
|
|
|
"pilot_languages": {
|
2016-08-18 14:11:02 +02:00
|
|
|
{Name: "pilot_id", Type: "int", DBType: "integer"},
|
2016-08-23 05:38:43 +02:00
|
|
|
{Name: "language_id", Type: "int", DBType: "integer"},
|
2016-08-18 07:26:24 +02:00
|
|
|
},
|
|
|
|
}[tableName], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ForeignKeyInfo returns a list of mock foreignkeys
|
2016-09-08 23:23:10 +02:00
|
|
|
func (m *MockDriver) ForeignKeyInfo(schema, tableName string) ([]bdb.ForeignKey, error) {
|
2016-08-18 07:26:24 +02:00
|
|
|
return map[string][]bdb.ForeignKey{
|
|
|
|
"jets": {
|
2016-08-28 02:04:51 +02:00
|
|
|
{Table: "jets", Name: "jets_pilot_id_fk", Column: "pilot_id", ForeignTable: "pilots", ForeignColumn: "id", ForeignColumnUnique: true},
|
2016-08-24 08:28:49 +02:00
|
|
|
{Table: "jets", Name: "jets_airport_id_fk", Column: "airport_id", ForeignTable: "airports", ForeignColumn: "id"},
|
2016-08-18 07:26:24 +02:00
|
|
|
},
|
|
|
|
"licenses": {
|
2016-08-24 08:28:49 +02:00
|
|
|
{Table: "licenses", Name: "licenses_pilot_id_fk", Column: "pilot_id", ForeignTable: "pilots", ForeignColumn: "id"},
|
2016-08-18 07:26:24 +02:00
|
|
|
},
|
2016-08-23 05:38:43 +02:00
|
|
|
"pilot_languages": {
|
2016-08-24 08:28:49 +02:00
|
|
|
{Table: "pilot_languages", Name: "pilot_id_fk", Column: "pilot_id", ForeignTable: "pilots", ForeignColumn: "id"},
|
|
|
|
{Table: "pilot_languages", Name: "jet_id_fk", Column: "language_id", ForeignTable: "languages", ForeignColumn: "id"},
|
2016-08-18 07:26:24 +02:00
|
|
|
},
|
|
|
|
}[tableName], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TranslateColumnType converts a column to its "null." form if it is nullable
|
2016-08-18 14:11:02 +02:00
|
|
|
func (m *MockDriver) TranslateColumnType(c bdb.Column) bdb.Column {
|
|
|
|
p := &PostgresDriver{}
|
|
|
|
return p.TranslateColumnType(c)
|
2016-08-18 07:26:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// PrimaryKeyInfo returns mock primary key info for the passed in table name
|
2016-09-08 23:23:10 +02:00
|
|
|
func (m *MockDriver) PrimaryKeyInfo(schema, tableName string) (*bdb.PrimaryKey, error) {
|
2016-08-18 07:26:24 +02:00
|
|
|
return map[string]*bdb.PrimaryKey{
|
2016-08-18 14:11:02 +02:00
|
|
|
"pilots": {
|
|
|
|
Name: "pilot_id_pkey",
|
|
|
|
Columns: []string{"id"},
|
|
|
|
},
|
|
|
|
"airports": {
|
|
|
|
Name: "airport_id_pkey",
|
|
|
|
Columns: []string{"id"},
|
|
|
|
},
|
|
|
|
"jets": {
|
|
|
|
Name: "jet_id_pkey",
|
|
|
|
Columns: []string{"id"},
|
|
|
|
},
|
|
|
|
"licenses": {
|
|
|
|
Name: "license_id_pkey",
|
|
|
|
Columns: []string{"id"},
|
|
|
|
},
|
|
|
|
"hangars": {
|
|
|
|
Name: "hangar_id_pkey",
|
|
|
|
Columns: []string{"id"},
|
|
|
|
},
|
2016-08-23 05:38:43 +02:00
|
|
|
"languages": {
|
|
|
|
Name: "language_id_pkey",
|
|
|
|
Columns: []string{"id"},
|
|
|
|
},
|
|
|
|
"pilot_languages": {
|
|
|
|
Name: "pilot_languages_pkey",
|
|
|
|
Columns: []string{"pilot_id", "language_id"},
|
2016-08-18 07:26:24 +02:00
|
|
|
},
|
|
|
|
}[tableName], nil
|
|
|
|
}
|
|
|
|
|
2016-09-05 13:28:58 +02:00
|
|
|
// UseLastInsertID returns a database mock LastInsertID compatibility flag
|
2016-08-18 14:11:02 +02:00
|
|
|
func (m *MockDriver) UseLastInsertID() bool { return false }
|
2016-08-18 07:26:24 +02:00
|
|
|
|
|
|
|
// Open mimics a database open call and returns nil for no error
|
2016-08-18 14:11:02 +02:00
|
|
|
func (m *MockDriver) Open() error { return nil }
|
2016-08-18 07:26:24 +02:00
|
|
|
|
|
|
|
// Close mimics a database close call
|
2016-08-18 14:11:02 +02:00
|
|
|
func (m *MockDriver) Close() {}
|
2016-09-09 19:14:18 +02:00
|
|
|
|
|
|
|
// RightQuote is the quoting character for the right side of the identifier
|
2016-09-09 19:30:46 +02:00
|
|
|
func (m *MockDriver) RightQuote() byte {
|
|
|
|
return '"'
|
2016-09-09 19:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// LeftQuote is the quoting character for the left side of the identifier
|
2016-09-09 19:30:46 +02:00
|
|
|
func (m *MockDriver) LeftQuote() byte {
|
|
|
|
return '"'
|
2016-09-09 19:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// IndexPlaceholders returns true to indicate fake support of indexed placeholders
|
|
|
|
func (m *MockDriver) IndexPlaceholders() bool {
|
|
|
|
return false
|
|
|
|
}
|