Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sbstnerhrdt/go-gorm-all-sql
generic sql connector for the grom framework
https://github.com/sbstnerhrdt/go-gorm-all-sql
connector databases golang gorm mysql postgres sql sqlite
Last synced: about 1 month ago
JSON representation
generic sql connector for the grom framework
- Host: GitHub
- URL: https://github.com/sbstnerhrdt/go-gorm-all-sql
- Owner: SbstnErhrdt
- License: mit
- Created: 2020-09-04T15:52:43.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-29T18:17:20.000Z (almost 2 years ago)
- Last Synced: 2024-11-16T03:19:26.745Z (about 1 month ago)
- Topics: connector, databases, golang, gorm, mysql, postgres, sql, sqlite
- Language: Go
- Homepage:
- Size: 71.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gorm - Connect to all databases (Work in Progress)
This is a generic connector interface for the following databases:
* MySQL
* Postgres
* SQLiteWith this connector, it is easy to run your sql based golang software, written with the gorm.io framework, on different
databases, by only changing one environment variable.Just set `SQL_TYPE` to either `MYSQL`, `POSTGRES`, `SQLITE` and you are good to go.
## Installation
```shell
go get github.com/SbstnErhrdt/go-gorm-all-sql
```In a development setting you can make use of the `env` package to load variables from a .env file into the ENV.
```shell
go get github.com/SbstnErhrdt/env
```## Examples
```go
package mainimport (
"github.com/SbstnErhrdt/go-gorm-all-sql/pkg/sql"
)func main() {
// load env
env.LoadEnvFiles() // reads the .env file in the working directory
// connect to DB
db, err := sql.ConnectToDatabase()
}
```## Todo
* Tests
* Docker compose environment## MySQL
Env variables
```
SQL_TYPE=MYSQL
SQL_HOST=mysql.server.com
SQL_PORT=3306
SQL_USER=sql_user
SQL_PASSWORD=xxxxxx
SQL_DATABASE=test
```## Postgres
```
SQL_TYPE=POSTGRES
SQL_HOST=postgres.server.com
SQL_PORT=5432
SQL_USER=sql_user
SQL_PASSWORD=xxxxxx
SQL_DATABASE=test
SQL_SSL= // optional
```## SQLite
```
SQL_TYPE=SQLITE
SQL_DATABASE=data.db
```## Logger
to add the logrus logger, add the following environment flag
```
SQL_LOGGER=LOGRUS
```## Functionality
* Works with different SQL dialects
* Checks if necessary environment variables are present
* Retries multiple times, if there is no connection available## Test
### MySQL
```
docker-compose run --rm
```