Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tessig/flamingo-mysql
A simple MySQL integration for Flamingo
https://github.com/tessig/flamingo-mysql
flamingo flamingo-module go hacktoberfest mysql
Last synced: about 1 month ago
JSON representation
A simple MySQL integration for Flamingo
- Host: GitHub
- URL: https://github.com/tessig/flamingo-mysql
- Owner: tessig
- License: mit
- Created: 2019-05-25T22:47:23.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-09T01:12:16.000Z (2 months ago)
- Last Synced: 2024-09-09T02:31:47.933Z (2 months ago)
- Topics: flamingo, flamingo-module, go, hacktoberfest, mysql
- Language: Go
- Homepage:
- Size: 148 KB
- Stars: 7
- Watchers: 1
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: Readme.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# Flamingo MySQL module
[![Go Report Card](https://goreportcard.com/badge/github.com/tessig/flamingo-mysql)](https://goreportcard.com/report/github.com/tessig/flamingo-mysql)
[![GoDoc](https://godoc.org/github.com/tessig/flamingo-mysql?status.svg)](https://godoc.org/github.com/tessig/flamingo-mysql)
[![Tests](https://github.com/tessig/flamingo-mysql/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/tessig/flamingo-mysql/actions/workflows/main.yml?query=branch%3Amaster+workflow%3ATests)
[![Release](https://img.shields.io/github/release/tessig/flamingo-mysql?style=flat-square)](https://github.com/tessig/flamingo-mysql/releases)This flamingo module provides a simple MySQL implementation by wrapping
github.com/jmoiron/sqlx and a migration tool by wrapping github.com/golang-migrate/migrate
as [Flamingo](https://www.flamingo.me/) Modules.## DB Module
The DB Flamingo module provides the interface `DB` and binds an sqlx connection
as singleton to it. The module will panic on startup when the connection can't be established.### Configuration
```yaml
db:
host: "host"
port: "3306" # must be a string!
databaseName: "databaseName"
user: "user"
password: "password"
maxConnectionLifetime: 0 # in seconds, 0 means to set nothing, negative values mean unlimited
# a set of additional connection options which are added as parameters to the DB URL
connectionOptions:
myOption1: "myValue1" # all option values must be strings
myOption2: "false"
```## Migration Module
The migration module relies on the db module and can handle schema migration and data seeding scripts. Both must be
provided as simple SQL scripts.The module provides additional Flamingo commands as entrypoints:
* `migrate [up|down] (-s[number of steps])`
* `seed`### Configuration
```yaml
migrations:
automigrate: false,
directory: "sql/migrations/",
seeds:
directory: "sql/seeds/",
```The Migration Module also adds `"db.connectionOptions.multiStatements": "true"` to the db configuration
to handle migration and seed scripts.### Migration
Migration scripts must be placed into the configured directory. For each migration,
there must be an "up" and a "down" script. Please refer to [github.com/golang-migrate/migrate](https://github.com/golang-migrate/migrate)
for more detailed documentation.If you set the `automigrate` config to `true`, flamingo will run a `migrate up` on each application start (`flamingo.StartupEvent`).
### Seeding
Seeding scripts must be placed into the configured directory. The seed command runs all
scripts in lexical order (see [filepath.Walk](https://godoc.org/path/filepath#Walk)).### Example directory structure:
```
sql
├── migrations
│ ├── 1_usertable.up.sql
│ ├── 1_usertable.down.sql
│ ├── 2_other-table.up.sql
│ ├── 2_other-table.down.sql
│ ├── 3_usertable-addColumn.up.sql
│ └── 3_usertable-addColumn.down.sql
└── seeds
├── users.sql
└── other-data.sql
```