/core-sql

Tools for connecting to, and working with an SQL database.

Primary LanguageGoApache License 2.0Apache-2.0

License Go Report Card Build Status GoDoc

Core SQL

This package is used to wrap the SQL standard library to satisfy the health checking server in the LUSH core service library. We use golang-migrate/migrate version 4 for migrations and treats it as a direct dependency.

Examples

Use in conjunction with readysrv

database := coresql.MustOpen("mysql", "tcp(localhost:3306)/mydb")
readysrv.New(readysrv.Checks{
    "mysql": database,
})

Ensure database is migrated up

_, migrations := coresql.MustOpenWithMigrations("mysql", "tcp(localhost:3306)/mydb", "file://path/to/migrations")
coresql.MustMigrateUp(migrations)

Handle migration arguments

You can force your application to respect migration command line arguments:

  • migrate up: attempt to migrate up
  • migrate down: attempt to migrate down
_, migrations := coresql.MustOpenWithMigrations("mysql", "tcp(localhost:3306)/mydb", "file://path/to/migrations")
coresql.HandleMigrationArgs(migrations)