{"id":16049280,"url":"https://github.com/ayan4m1/pg-redis","last_synced_at":"2025-03-18T04:31:08.591Z","repository":{"id":27900877,"uuid":"31392549","full_name":"ayan4m1/pg-redis","owner":"ayan4m1","description":null,"archived":false,"fork":false,"pushed_at":"2021-09-18T20:19:01.000Z","size":347,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-23T23:26:37.971Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ayan4m1.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2015-02-26T22:37:50.000Z","updated_at":"2023-04-05T21:19:46.000Z","dependencies_parsed_at":"2022-08-26T01:11:25.301Z","dependency_job_id":null,"html_url":"https://github.com/ayan4m1/pg-redis","commit_stats":null,"previous_names":["bulletlogic/pg-redis"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayan4m1%2Fpg-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayan4m1%2Fpg-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayan4m1%2Fpg-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayan4m1%2Fpg-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ayan4m1","download_url":"https://codeload.github.com/ayan4m1/pg-redis/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243902277,"owners_count":20366259,"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":[],"created_at":"2024-10-09T00:15:41.200Z","updated_at":"2025-03-18T04:31:08.216Z","avatar_url":"https://github.com/ayan4m1.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pg-redis\n\nA pg query wrapper with implicit redis query caching.\n\n## Installation\n\n    npm i --save pg-redis pg redis\n\n## Usage\n\n    var pgRedis = require('pg-redis');\n    pgRedis.init({\n        // a node-postgres config object, documented at\n        // https://github.com/brianc/node-postgres/wiki/Client#parameters\n    });\n\n    // normal usage, caches the result for two minutes\n    pgRedis.query('select * from entity', {\n      duration: 120\n    }).then(function (results) {\n      console.log(results);\n    }, function (error) {\n      console.error(error);\n    }).done();\n\n    // bypassing the cache in favor of the prepare/execute api\n    pgRedis.prepare('select * from entity where date between ? and ?').then(function (stmt) {\n      stmt.execute([startDate, endDate]).then(function (results) {\n        console.log(results);\n      }).done();\n    }).done();\n\n    // efficient batching operations can be done this way\n    // pass batch:true in prepare options to initiate a new batch operation\n    pgRedis.prepare('begin; create temporary table temp_table like (table)', {batch:true}).then(function (stmt) {\n        // we must call release() when done with the transaction\n        // stmt.release is only defined for the first prepared statement in a chain with {batch:true}\n        var release = stmt.release;\n        stmt.execute().then(function () {\n            pgRedis.prepare('insert into temp_table values ($1, $2, $3)', {client:stmt.client}, function(stmt) {\n                var data = [[1,2,3], [4,5,6], [7,8,9]],\n                    inserts = [];\n\n                // build an array of promises to insert individual rows\n                for (var i = 0; i \u003c data.length; i++) {\n                    inserts.push(stmt.execute(data[i]));\n                }\n\n                // perform inserts in parallel using the same connection\n                p.all(inserts).then(function () {\n                    // make sure that release() is called regardless of success or failure\n                    pgRedis.prepare('select merge_data(); commit;').then(function (stmt) {\n                        // release the connection regardless of commit result\n                        stmt.execute().then(null, function (err) {\n                            console.error('an error occurred executing the merge statement', err);\n                        }).fin(function () { release(); }).done();\n                    }, function (err) {\n                        console.error('an error occurred preparing the merge statement', err);\n                    }).done();\n                }, function (err) {\n                    console.error('an error occurred during the insertion of data', err);\n                }).done();\n            }, function (err) {\n                console.error('an error occurred preparing the insert statement', err);\n            }).done();\n        }, function (err) {\n            console.error('an error occurred preparing the temporary table creation statement', err);\n        }).done();\n    }).done();\n\n## Testing\n\n    npm test\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayan4m1%2Fpg-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fayan4m1%2Fpg-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayan4m1%2Fpg-redis/lists"}