generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.go
73 lines (61 loc) · 2.05 KB
/
product.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package sqltest
import (
"context"
"database/sql"
)
// Product is a specific database product such as MySQL or MariaDB.
//
// The product correlates with a running service that tests are run against.
// Many products share a common wire protocol or are even entirely compatible.
type Product interface {
// Name returns the human-readable name of the product.
Name() string
// IsCompatibleWith return true if the product is compatible with d.
IsCompatibleWith(d Driver) bool
// DefaultDataSource returns the default data source to use to connect to
// the product.
//
// The returned data source must contain enough information to connect to
// the product when running under the sqltest Docker stack or under a CI
// workflow.
//
// d is the driver that is being used to connect to the product. If the
// driver can not be used to connect to this product it returns
// ErrIncompatibleDriver.
DefaultDataSource(d Driver) (DataSource, error)
}
// MultiDatabaseProduct is a product that supports multiple databases on the
// same "server" or endpoint.
type MultiDatabaseProduct interface {
Product
// CreateDatabase creates a new database with the given name.
CreateDatabase(ctx context.Context, db *sql.DB, name string) error
// DropDatabase drops the database with the given name.
DropDatabase(ctx context.Context, db *sql.DB, name string) error
}
var (
// MySQL is the Product for MySQL (https://www.mysql.com).
MySQL Product = MySQLCompatibleProduct{
ProductName: "MySQL",
DefaultPort: "23306",
}
// MariaDB is the Product for MariaDB (https://mariadb.org).
MariaDB Product = MySQLCompatibleProduct{
ProductName: "MariaDB",
DefaultPort: "23307",
}
// PostgreSQL is the Product for PostgreSQL (https://www.postgresql.org).
PostgreSQL Product = PostgresCompatibleProduct{
ProductName: "PostgreSQL",
DefaultPort: "25432",
}
// SQLite is the Product for SQLite (https://www.sqlite.org).
SQLite Product = sqliteProduct{}
// Products is a slice containing all known products.
Products = []Product{
MySQL,
MariaDB,
PostgreSQL,
SQLite,
}
)