-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs for pgxscan and sqlscan packages.
- Loading branch information
1 parent
fa97c22
commit b780922
Showing
5 changed files
with
92 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Package pgxscan allows scanning data from pgx.Rows into complex Go types. | ||
/* | ||
pgxscan is a wrapper around github.com/georgysavva/dbscan package. | ||
It contains adapters and proxy functions that are meant to connect github.com/jackc/pgx/v4 | ||
with github.com/georgysavva/dbscan functionality. pgxscan mirrors all capabilities provided by dbscan. | ||
See dbscan docs to get familiar with all details and features. | ||
How to use | ||
The most common way to use pgxscan is by calling QueryAll or QueryOne function, | ||
it's as simple as this: | ||
type User struct { | ||
ID string `db:"user_id"` | ||
Name string | ||
Email string | ||
Age int | ||
} | ||
db, _ := pgxpool.Connect(ctx, "example-connection-url") | ||
// Use QueryAll to query multiple records. | ||
var users []*User | ||
if err := pgxscan.QueryAll( | ||
ctx, &users, db, `SELECT user_id, name, email, age from users`, | ||
); err != nil { | ||
// Handle query or rows processing error. | ||
} | ||
// users variable now contains data from all rows. | ||
// Use QueryOne to query exactly one record. | ||
var user User | ||
if err := pgxscan.QueryOne( | ||
ctx, &user, db, `SELECT user_id, name, email, age from users where id='bob'`, | ||
); err != nil { | ||
// Handle query or rows processing error. | ||
} | ||
// users variable now contains data from all rows. | ||
*/ | ||
package pgxscan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Package sqlscan allows scanning data from *sql.Rows into complex Go types. | ||
/* | ||
sqlscan is a wrapper around github.com/georgysavva/dbscan package. | ||
It contains adapters and proxy functions that are meant to connect database/sql | ||
with github.com/georgysavva/dbscan functionality. sqlscan mirrors all capabilities provided by dbscan. | ||
See dbscan docs to get familiar with all details and features. | ||
How to use | ||
The most common way to use sqlscan is by calling QueryAll or QueryOne function, | ||
it's as simple as this: | ||
type User struct { | ||
ID string `db:"user_id"` | ||
Name string | ||
Email string | ||
Age int | ||
} | ||
db, _ := sql.Open("pgx", "example-connection-url") | ||
// Use QueryAll to query multiple records. | ||
var users []*User | ||
if err := sqlscan.QueryAll( | ||
ctx, &users, db, `SELECT user_id, name, email, age from users`, | ||
); err != nil { | ||
// Handle query or rows processing error. | ||
} | ||
// users variable now contains data from all rows. | ||
// Use QueryOne to query exactly one record. | ||
var user User | ||
if err := sqlscan.QueryOne( | ||
ctx, &user, db, `SELECT user_id, name, email, age from users where id='bob'`, | ||
); err != nil { | ||
// Handle query or rows processing error. | ||
} | ||
// users variable now contains data from all rows. | ||
*/ | ||
package sqlscan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters