{"id":15019651,"url":"https://github.com/gajus/slonik-interceptor-query-benchmarking","last_synced_at":"2025-09-07T06:06:33.113Z","repository":{"id":57363305,"uuid":"172088222","full_name":"gajus/slonik-interceptor-query-benchmarking","owner":"gajus","description":"Benchmarks Slonik queries.","archived":false,"fork":false,"pushed_at":"2020-02-13T07:39:44.000Z","size":27,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-31T14:37:48.380Z","etag":null,"topics":["postgresql","slonik"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gajus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-22T15:22:36.000Z","updated_at":"2024-09-11T17:42:53.000Z","dependencies_parsed_at":"2022-09-26T16:32:13.835Z","dependency_job_id":null,"html_url":"https://github.com/gajus/slonik-interceptor-query-benchmarking","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-benchmarking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-benchmarking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-benchmarking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-benchmarking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gajus","download_url":"https://codeload.github.com/gajus/slonik-interceptor-query-benchmarking/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233690488,"owners_count":18714783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["postgresql","slonik"],"created_at":"2024-09-24T19:53:50.634Z","updated_at":"2025-01-13T04:09:53.960Z","avatar_url":"https://github.com/gajus.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# slonik-interceptor-query-benchmarking\n\n[![Travis build status](http://img.shields.io/travis/gajus/slonik-interceptor-query-benchmarking/master.svg?style=flat-square)](https://travis-ci.org/gajus/slonik-interceptor-query-benchmarking)\n[![Coveralls](https://img.shields.io/coveralls/gajus/slonik-interceptor-query-benchmarking.svg?style=flat-square)](https://coveralls.io/github/gajus/slonik-interceptor-query-benchmarking)\n[![NPM version](http://img.shields.io/npm/v/slonik-interceptor-query-benchmarking.svg?style=flat-square)](https://www.npmjs.org/package/slonik-interceptor-query-benchmarking)\n[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)\n[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social\u0026label=Follow)](https://twitter.com/kuizinas)\n\nBenchmarks [Slonik](https://github.com/gajus/slonik) queries.\n\n## Implementation\n\nSummarizes all queries that were run during the life-time of a connection.\n\nExample output:\n\n```\n╔═══════════════════════════════════════════════════════════════╤═══════════╤═════════╤═══════╗\n║ Query                                                         │ Execution │ Average │ Total ║\n║                                                               │ count     │ time    │ time  ║\n╟───────────────────────────────────────────────────────────────┼───────────┼─────────┼───────╢\n║ SELECT id FROM seating_plan WHERE auditorium_id = $1 AND      │ 1         │ 176ms   │ 176ms ║\n║ fingerprint = $2                                              │           │         │       ║\n╟───────────────────────────────────────────────────────────────┼───────────┼─────────┼───────╢\n║ UPDATE event SET scrape_event_seating_session = $1,           │ 1         │ 176ms   │ 176ms ║\n║ scrape_event_seating_session_created_at = now() WHERE id =    │           │         │       ║\n║ $2                                                            │           │         │       ║\n╟───────────────────────────────────────────────────────────────┼───────────┼─────────┼───────╢\n║ SELECT v1.cinema_id \"cinemaId\",                               │ 1         │ 182ms   │ 182ms ║\n║ last_event_seating_plan_change.seating_plan_id                │           │         │       ║\n║ \"seatingPlanId\" FROM event e1 INNER JOIN venue v1 ON v1.id =  │           │         │       ║\n║ e1.venue_id INNER JOIN LATERAL ( SELECT DISTINCT ON           │           │         │       ║\n║ (espc1.event_id) espc1.seating_plan_id FROM                   │           │         │       ║\n║ event_seating_plan_change espc1 WHERE espc1.event_id = e1.id  │           │         │       ║\n║ ORDER BY espc1.event_id, espc1.id DESC )                      │           │         │       ║\n║ last_event_seating_plan_change ON TRUE WHERE e1.id = $1       │           │         │       ║\n╟───────────────────────────────────────────────────────────────┼───────────┼─────────┼───────╢\n║ UPDATE event_seating_lookup SET ended_at =                    │ 1         │ 185ms   │ 185ms ║\n║ statement_timestamp(), log = $1, lookup_is_successful = $2,   │           │         │       ║\n║ error_name = $3, error_message = $4, error = $5 WHERE id =    │           │         │       ║\n║ $6                                                            │           │         │       ║\n╟───────────────────────────────────────────────────────────────┼───────────┼─────────┼───────╢\n║ SELECT s1.id, s1.location_column \"locationColumn\",            │ 1         │ 237ms   │ 237ms ║\n║ s1.location_row \"locationRow\", sa1.fuid \"seatingAreaFuid\"     │           │         │       ║\n║ FROM seat s1 INNER JOIN seating_area sa1 ON sa1.id =          │           │         │       ║\n║ s1.seating_area_id WHERE s1.seating_plan_id = $1              │           │         │       ║\n╟───────────────────────────────────────────────────────────────┼───────────┼─────────┼───────╢\n║ SELECT extract(epoch from                                     │ 1         │ 647ms   │ 647ms ║\n║ (c1.maximum_event_seating_lookup_duration)) FROM event e1     │           │         │       ║\n║ INNER JOIN venue v1 ON v1.id = e1.venue_id INNER JOIN cinema  │           │         │       ║\n║ c1 ON c1.id = v1.cinema_id WHERE e1.id = $1                   │           │         │       ║\n╟───────────────────────────────────────────────────────────────┼───────────┼─────────┼───────╢\n║ SELECT id FROM cinema_foreign_seat_type WHERE cinema_id = $1  │ 133       │ 150ms   │ 19.9s ║\n║ AND fuid = $2                                                 │           │         │       ║\n╚═══════════════════════════════════════════════════════════════╧═══════════╧═════════╧═══════╝\n\n```\n\n## API\n\n```js\nimport {\n  createQueryBenchmarkingInterceptor\n} from 'slonik';\n\n```\n\n```js\n/**\n * @property targetConnectionTypes Dictates what connections to benchmark. (Default: [EXPLICIT])\n */\ntype UserConfigurationType = {|\n  +targetConnectionTypes: $ReadOnlyArray\u003cConnecionTypeType\u003e\n|};\n\n(userConfiguration: UserConfigurationType) =\u003e InterceptorType;\n\n```\n\n## Example usage\n\n```js\nimport {\n  createPool\n} from 'slonik';\nimport {\n  createQueryBenchmarkingInterceptor\n} from 'slonik-interceptor-query-benchmarking';\n\nconst interceptors = [\n  createQueryBenchmarkingInterceptor()\n];\n\nconst pool = createPool('postgres://', {\n  interceptors\n});\n\npool.connect((connection) =\u003e {\n  return connection.any(sql`\n    SELECT\n      id,\n      code_alpha_2\n    FROM country\n  `);\n});\n\n```\n\nProduces log:\n\n```sql\n╔═════════════════╤═══════════╤═════════╤═══════╗\n║ Query           │ Execution │ Average │ Total ║\n║                 │ count     │ time    │ time  ║\n╟─────────────────┼───────────┼─────────┼───────╢\n║ SELECT          │ 1         │ 25ms    │ 25ms  ║\n║    id,          │           │         │       ║\n║    code_alpha_2 │           │         │       ║\n║ FROM            │           │         │       ║\n║    country      │           │         │       ║\n╚═════════════════╧═══════════╧═════════╧═══════╝\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fslonik-interceptor-query-benchmarking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgajus%2Fslonik-interceptor-query-benchmarking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fslonik-interceptor-query-benchmarking/lists"}