-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#110 code example to connect to database
- Loading branch information
Reindert Vetter
committed
May 6, 2021
1 parent
bd79fdc
commit ae26e9c
Showing
5 changed files
with
76 additions
and
10 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
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,59 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/confetti-framework/contract/inter" | ||
"github.com/confetti-framework/foundation/db" | ||
"github.com/confetti-framework/support/env" | ||
"time" | ||
) | ||
|
||
var Database = struct { | ||
Default string | ||
Connections map[string]inter.Connection | ||
}{ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default Database Connection Name | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you may specify which of the database connections below you wish | ||
| to use as your default connection for all database work. Of course | ||
| you may use many connections at once. | ||
| | ||
*/ | ||
Default: env.StringOr("DB_CONNECTION", "mysql"), | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Database Connections | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here are each of the database connections setup for your application. | ||
| Of course, examples of configuring each database platform that is | ||
| supported by Confetti is shown below to make development simple. | ||
| | ||
*/ | ||
|
||
Connections: map[string]inter.Connection{ | ||
"mysql": &db.MySQL{ | ||
Host: env.StringOr("DB_HOST", "127.0.0.1"), | ||
Port: env.IntOr("DB_PORT", 3306), | ||
Database: env.StringOr("DB_DATABASE", "confetti"), | ||
Username: env.StringOr("DB_USERNAME", "app"), | ||
Password: env.StringOr("DB_PASSWORD", ""), | ||
QueryTimeout: 10 * time.Second, | ||
}, | ||
|
||
/* | ||
"postgresql": &db.PostgreSQL{ | ||
Host: env.StringOr("DB_HOST", "127.0.0.1"), | ||
Port: env.IntOr("DB_PORT", 5432), | ||
Database: env.StringOr("DB_DATABASE", "confetti"), | ||
Username: env.StringOr("DB_USERNAME", "app"), | ||
Password: env.StringOr("DB_PASSWORD", ""), | ||
QueryTimeout: 10 * time.Second, | ||
}, | ||
*/ | ||
}, | ||
} |
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