This is a small library to have a CRUD actions over a DB engine. It uses https://gorm.io.
type User struct {
Id uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
Name string `json:"name"`
Email string `json:"email"`
}
func main() {
// db := //Setup DB connection.
var repo *CrudRepository = NewCrudRepository(db, User{}, uuid.UUID{})
// Save
user, _:= repo.Save(&User{
Name: "John",
Email: "john@email.com",
})
// Find
result, _ := repo.FindById(user.Id)
// That's it.
}
-
❏ Save (Upsert)
-
❏ SaveAll, DeleteAll
-
❏ Add Tags for:
RAW SQL
andFindBy
actions.type User struct { Id uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;default:gen_random_uuid()"` Name string `json:"name" query:'SELECT * FROM users where Name = ?'` Email string `json:"email" findBy:'Email'` }