Skip to content

Instantly share code, notes, and snippets.

View ryantbrown's full-sized avatar

Ryan Brown ryantbrown

View GitHub Profile
@ryantbrown
ryantbrown / es-nested-agg-nested-query.json
Last active February 27, 2018 19:39
Elastic search nested aggregate with nested query
GET influencers/_search
{
"size": 0,
"aggregations": {
"influencers": {
"nested": {
"path": "interests"
},
"aggs": {
"names": {
@ryantbrown
ryantbrown / typescript-postgres-error-codes.ts
Created May 9, 2025 17:57
TypeScript object of PostgreSQL error codes
/**
* Database (PostgreSQL) error codes.
*/
export const DatabaseErrorCode = {
SuccessfulCompletion: "00000",
Warning: "01000",
DynamicResultSetsReturned: "0100C",
ImplicitZeroBitPadding: "01008",
NullValueEliminatedInSetFunction: "01003",
PrivilegeNotGranted: "01007",
@ryantbrown
ryantbrown / with-pg-error-handling.ts
Last active June 14, 2025 23:49
TypeScript Postgres Error Handling
import { DatabaseError } from "pg";
import { DatabaseErrorCode } from "./errors";
/**
* Higher order function with fine-grained error handling.
*/
export async function withErrorHandling<T>(
fn: () => Promise<T>,
onError: Record<string, (error: PgDatabaseError) => void>,
) {