diff --git a/README.md b/README.md index 4823206..4aafa77 100644 --- a/README.md +++ b/README.md @@ -41,4 +41,38 @@ Plain SQL queries are not inherently bad but come with challenges: Run the following command to generate schema files: ```bash -go run code.partial.tech/go/pgm/cmd -o ./db ./schema.sql \ No newline at end of file +go run code.partial.tech/go/pgm/cmd -o ./db ./schema.sql +``` +once you have the schama files created you can use `pgm` as + +```go +package main + +import "code.partial.tech/go/pgm" + +type MyModel struct { + ID string + Email string +} + +func main() { + println("Initializing pgx connection pool") + pgm.InitPool(pgm.Config{ + ConnString: url, + }) + + // Select query to fetch the first record + // Assumes the schema is defined in the "db" package with a User table + var v MyModel + err := db.User.Select(db.User.ID, db.User.Email). + Where(db.User.Email.Like("anki%")). + First(context.TODO(), &v.ID, &v.Email) + if err != nil { + println("Error:", err.Error()) + return + } + + println("User email:", v.Email) +} +``` +