Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector connects to a Cloud SQL instance using the Cloud SQL Proxy.
Example ¶
config, err := pgxpool.ParseConfig(os.Getenv("PGX_DATABASE_URL")) if err != nil { panic(err) } ctx := context.TODO() // Create a new pgxgcp.Connector connector, err := pgxgcp.Connect(ctx) if err != nil { panic(err) } // Set BeforeConnect hook to pgxaws.BeforeConnect config.BeforeConnect = connector.BeforeConnect // Create a new pgxpool with the config conn, err := pgxpool.NewWithConfig(ctx, config) if err != nil { panic(err) } rows, err := conn.Query(ctx, "SELECT * from organization") if err != nil { panic(err) } // close the rows defer rows.Close() // Organization struct must be defined type Organization struct { Name string `db:"name"` } for rows.Next() { organization, err := pgx.RowToStructByName[Organization](rows) if err != nil { panic(err) } fmt.Println(organization.Name) }
type DatastoreQuery ¶
type DatastoreQuery struct { ID string `datastore:"query_id,hash"` Data []byte `datastore:"query_data"` ExpireAt time.Time `datastore:"query_expire_at"` }
DatastoreQuery represents a record in the dynamodb table.
type DatastoreQueryCacher ¶
type DatastoreQueryCacher struct { // Client is the Datastore client. Client *datastore.Client // Kind is the name of the kind in Datastore. Kind string }
DatastoreQueryCacher implements pgxcache.QueryCacher interface to use Google Datastore.
Example ¶
config, err := pgxpool.ParseConfig(os.Getenv("PGX_DATABASE_URL")) if err != nil { panic(err) } conn, err := pgxpool.NewWithConfig(context.TODO(), config) if err != nil { panic(err) } // close the connection defer conn.Close() // Create a new client client, err := datastore.NewClient(context.TODO(), os.Getenv("GOOGLE_PROJECT_ID")) if err != nil { panic(err) } // Create a new cacher cacher := &pgxgcp.DatastoreQueryCacher{ Client: client, Kind: "queries", } // create a new querier querier := &pgxcache.Querier{ // set the default query options, which can be overridden by the query // -- @cache-max-rows 100 // -- @cache-ttl 30s Options: &pgxcache.QueryOptions{ MaxLifetime: 30 * time.Second, MaxRows: 1, }, Cacher: cacher, Querier: conn, } rows, err := querier.Query(context.TODO(), "SELECT * from customer") if err != nil { panic(err) } // close the rows defer rows.Close() // Customer struct must be defined type Customer struct { FirstName string `db:"first_name"` LastName string `db:"last_name"` } for rows.Next() { customer, err := pgx.RowToStructByName[Customer](rows) if err != nil { panic(err) } fmt.Println(customer.FirstName) }
func (*DatastoreQueryCacher) Get ¶
func (r *DatastoreQueryCacher) Get(ctx context.Context, key *pgxcache.QueryKey) (*pgxcache.QueryItem, error)
Get gets a cache item from Google Datastore. Returns pointer to the item, a boolean which represents whether key exists or not and an error.
type FirestoreQuery ¶
type FirestoreQuery struct { ID string `firestore:"query_id,hash"` Data []byte `firestore:"query_data"` ExpireAt time.Time `firestore:"query_expire_at"` }
FirestoreQuery represents a record in the dynamodb table.
type FirestoreQueryCacher ¶
type FirestoreQueryCacher struct { // Client is the Firestore client. Client *firestore.Client // Collection is the name of the collection in Firestore. Collection string }
FirestoreQueryCacher implements pgxcache.QueryCacher interface to use Google Firestore.
Example ¶
config, err := pgxpool.ParseConfig(os.Getenv("PGX_DATABASE_URL")) if err != nil { panic(err) } conn, err := pgxpool.NewWithConfig(context.TODO(), config) if err != nil { panic(err) } // close the connection defer conn.Close() // Create a new client client, err := firestore.NewClient(context.TODO(), os.Getenv("GOOGLE_PROJECT_ID")) if err != nil { panic(err) } // Create a new cacher cacher := &pgxgcp.FirestoreQueryCacher{ Client: client, Collection: "queries", } // create a new querier querier := &pgxcache.Querier{ // set the default query options, which can be overridden by the query // -- @cache-max-rows 100 // -- @cache-ttl 30s Options: &pgxcache.QueryOptions{ MaxLifetime: 30 * time.Second, MaxRows: 1, }, Cacher: cacher, Querier: conn, } rows, err := querier.Query(context.TODO(), "SELECT * from customer") if err != nil { panic(err) } // close the rows defer rows.Close() // Customer struct must be defined type Customer struct { FirstName string `db:"first_name"` LastName string `db:"last_name"` } for rows.Next() { customer, err := pgx.RowToStructByName[Customer](rows) if err != nil { panic(err) } fmt.Println(customer.FirstName) }
func (*FirestoreQueryCacher) Get ¶
func (r *FirestoreQueryCacher) Get(ctx context.Context, key *pgxcache.QueryKey) (*pgxcache.QueryItem, error)
Get gets a cache item from Google Firestore. Returns pointer to the item, a boolean which represents whether key exists or not and an error.
type StorageQueryCacher ¶
type StorageQueryCacher struct { // Client to interact with S3 Client *storage.Client // Bucket name in S3 Bucket string }
StorageQueryCacher implements pgxcache.QueryCacher interface to use Google Cloud Storage.
Example ¶
config, err := pgxpool.ParseConfig(os.Getenv("PGX_DATABASE_URL")) if err != nil { panic(err) } conn, err := pgxpool.NewWithConfig(context.TODO(), config) if err != nil { panic(err) } // close the connection defer conn.Close() // Create a new client client, err := storage.NewClient(context.TODO()) if err != nil { panic(err) } // Create a new cacher cacher := &pgxgcp.StorageQueryCacher{ Client: client, Bucket: "queries", } // create a new querier querier := &pgxcache.Querier{ // set the default query options, which can be overridden by the query // -- @cache-max-rows 100 // -- @cache-ttl 30s Options: &pgxcache.QueryOptions{ MaxLifetime: 30 * time.Second, MaxRows: 1, }, Cacher: cacher, Querier: conn, } rows, err := querier.Query(context.TODO(), "SELECT * from customer") if err != nil { panic(err) } // close the rows defer rows.Close() // Customer struct must be defined type Customer struct { FirstName string `db:"first_name"` LastName string `db:"last_name"` } for rows.Next() { customer, err := pgx.RowToStructByName[Customer](rows) if err != nil { panic(err) } fmt.Println(customer.FirstName) }
func (*StorageQueryCacher) Get ¶
func (r *StorageQueryCacher) Get(ctx context.Context, key *pgxcache.QueryKey) (*pgxcache.QueryItem, error)
Get implements pgxcache.QueryCacher.