https://github.com/pengux/sqlassert
Go package with assertion helpers for SQL databases
https://github.com/pengux/sqlassert
Last synced: 8 months ago
JSON representation
Go package with assertion helpers for SQL databases
- Host: GitHub
- URL: https://github.com/pengux/sqlassert
- Owner: pengux
- License: mit
- Created: 2021-08-02T07:19:14.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-20T09:00:59.000Z (over 3 years ago)
- Last Synced: 2024-06-19T20:51:01.590Z (over 1 year ago)
- Language: Go
- Size: 57.6 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://pkg.go.dev/github.com/pengux/sqlassert)
[](https://goreportcard.com/report/github.com/pengux/sqlassert)
# sqlassert
Go package with assertion helpers for SQL databases
Use `sqlassert` in your integration tests or write assertions for schema changes and migraton scripts.
## Usage
```
go get github.com/pengux/sqlassert
```
Example:
```
package migration_test
import (
"testing"
"github.com/pengux/sqlassert"
)
func TestMigration(t *testing.T) {
...
// db is *sql.DB
pgassert := sqlassert.NewPostgresAsserter(db)
table := "table_name"
column := "column_name"
index := "index_name"
constraint := "constraint_name"
id := "123"
pgassert.TableExists(t, table)
pgassert.ColumnExists(t, table, column)
pgassert.ConstraintExists(t, table, column, constraint)
pgassert.RowExists(t, table, map[string]interface{}{
"id": id,
})
pgassert.IndexExists(t, table, index)
}
```
## Supported databases
- [x] Postgresql
- [x] Mysql
- [ ] SQLite
- [ ] Microsoft SQL Server
- [ ] Oracle