felipeg48 / go-commons-data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Data Commons for GORM

This is a small library to have a CRUD actions over a DB engine. It uses https://gorm.io.

Example

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.
}

NEXT Releases

  • ❏ Save (Upsert)

  • ❏ SaveAll, DeleteAll

  • ❏ Add Tags for: RAW SQL and FindBy 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'`
    }

Versions

Version Notes

v0.0.1

Initial Commit

Latest Push: v0.0.1

About


Languages

Language:Go 100.0%