https://github.com/realtemirov/repoimpl
Repositories, migrations and tests with model
https://github.com/realtemirov/repoimpl
go golang migration migrations repository testing
Last synced: 28 days ago
JSON representation
Repositories, migrations and tests with model
- Host: GitHub
- URL: https://github.com/realtemirov/repoimpl
- Owner: realtemirov
- License: mit
- Created: 2023-03-27T19:14:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-14T12:03:07.000Z (about 3 years ago)
- Last Synced: 2025-12-18T23:33:38.407Z (6 months ago)
- Topics: go, golang, migration, migrations, repository, testing
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# repoimpl
Repositories, migrations and tests with model
We write the necessary model.
The function writes table queries, repositories and tests for each model in the migrations folder.
## Install
```
go get github.com/realtemirov/repoimpl
```
## Repository
```
type User struct {
Username string
Password string
}
err := repoimpl.NewRepository(User{})
if err != nil {
panic(err)
}
```
Repository implement CRUD to *postgres* database with sql package and creates **interface storage**
```
go run main.go
```
├─ repository \
─ postgres \
─ user.go - CRUD methods \
─ storage.go - CRUD interfaces
## Migrations
```
type User struct {
Username string
Password string
}
err := repoimpl.NewMigration(User{})
if err != nil {
panic(err)
}
```
Creates **migration_user.sql** in the **migrations** folder
```
go run main.go
```
```
CREATE TABLE IF NOT EXITS "users" (
"username" TEXT,
"password" TEXT
);
```
If **db** is written **tag** it will be written by tag
```
type User struct {
Username string `db:"user_name"`
Password string `db:"pass_word"`
}
err := repoImpl.NewDBTable(User{})
if err != nil {
panic(err)
}
```
**migration_user.sql**
```
CREATE TABLE IF NOT EXITS "users" (
"user_name" TEXT,
"pass_word" TEXT
);
```