{"id":14973991,"url":"https://github.com/mrdulin/nodejs-pg-knex-samples","last_synced_at":"2025-10-27T05:31:22.900Z","repository":{"id":35837280,"uuid":"157507545","full_name":"mrdulin/nodejs-pg-knex-samples","owner":"mrdulin","description":"Learning PostgreSQL, knex.js by examples.","archived":false,"fork":false,"pushed_at":"2022-12-30T02:56:20.000Z","size":2464,"stargazers_count":5,"open_issues_count":4,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T02:41:22.743Z","etag":null,"topics":["knex","knexjs","knexjswithpostgresql","nodejs","pgsql","postgresql","postgresql-database","sql"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/mrdulin.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":"2018-11-14T07:19:28.000Z","updated_at":"2023-04-06T21:37:42.000Z","dependencies_parsed_at":"2023-01-16T07:30:40.660Z","dependency_job_id":null,"html_url":"https://github.com/mrdulin/nodejs-pg-knex-samples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdulin%2Fnodejs-pg-knex-samples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdulin%2Fnodejs-pg-knex-samples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdulin%2Fnodejs-pg-knex-samples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdulin%2Fnodejs-pg-knex-samples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrdulin","download_url":"https://codeload.github.com/mrdulin/nodejs-pg-knex-samples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238445830,"owners_count":19473820,"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":["knex","knexjs","knexjswithpostgresql","nodejs","pgsql","postgresql","postgresql-database","sql"],"created_at":"2024-09-24T13:49:47.595Z","updated_at":"2025-10-27T05:31:22.048Z","avatar_url":"https://github.com/mrdulin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nodejs-pg-knex-samples\n\nLearning PostgreSQL, knex.js by examples.\n\n## Usage\n\n```txt\nSQL_HOST=127.0.0.1\nSQL_DATABASE=nodejs-pg-knex-samples\nSQL_USER=sampleadmin\nSQL_PORT=5431\nSQL_PASSWORD=sampleadmin\nSQL_SSL=false\n```\n\nstart `pg` docker container\n\n```bash\ndocker-compose up -d\n```\n\naccess docker container\n\n```bash\ndocker exec -it \u003cContainer Id\u003e bash\n```\n\nconnect `postgres` using `psql`\n\n```bash\npsql -U sampleadmin nodejs-pg-knex-samples\n```\n\nlist all relations\n\n```bahs\nnodejs-pg-knex-samples-# \\d\n                        List of relations\n Schema |              Name              |   Type   |    Owner\n--------+--------------------------------+----------+-------------\n public | books                          | table    | sampleadmin\n public | books_book_id_seq              | sequence | sampleadmin\n public | knex_migrations                | table    | sampleadmin\n public | knex_migrations_id_seq         | sequence | sampleadmin\n public | knex_migrations_lock           | table    | sampleadmin\n public | knex_migrations_lock_index_seq | sequence | sampleadmin\n(6 rows)\n```\n\nTest example:\n\n```bash\ncd src/window-function\n```\n\ncreate migration files\n\n```bash\n☁  window-function [master] ⚡  npx knex migrate:make init --knexfile ./knexfile.ts\n```\n\ncreate seed files\n\n```bash\n☁  window-function [master] ⚡  npx knex seed:make initialize_db --knexfile ./knexfile.ts -x ts\n```\n\nmigrate database\n\n```bash\nwindow-function [master] ⚡  npx knex migrate:latest\n```\n\nseed database\n\n```bash\n☁  window-function [master] ⚡  npx knex seed:run\n```\n\ncheck postgresql database files\n\n```bash\nroot@f29a16a93352:/# ls /db-data/pgdata/\nbase\tpg_clog       pg_dynshmem  pg_ident.conf  pg_multixact\tpg_replslot  pg_snapshots  pg_stat_tmp\tpg_tblspc    PG_VERSION  postgresql.auto.conf  postmaster.opts\nglobal\tpg_commit_ts  pg_hba.conf  pg_logical\t  pg_notify\tpg_serial    pg_stat\t   pg_subtrans\tpg_twophase  pg_xlog\t postgresql.conf       postmaster.pid\n```\n\n## pgbench\n\ninitialize testing datas\n\n```bash\nroot@f29a16a93352:/# pgbench -i -s 2 -F 80 -U sampleadmin -d nodejs-pg-knex-samples\nNOTICE:  table \"pgbench_history\" does not exist, skipping\nNOTICE:  table \"pgbench_tellers\" does not exist, skipping\nNOTICE:  table \"pgbench_accounts\" does not exist, skipping\nNOTICE:  table \"pgbench_branches\" does not exist, skipping\ncreating tables...\n100000 of 200000 tuples (50%) done (elapsed 2.29 s, remaining 2.29 s)\n200000 of 200000 tuples (100%) done (elapsed 4.90 s, remaining 0.00 s)\nvacuum...\nset primary keys...\ndone.\n```\n\n## knex workflow\n\n[knex workflow](./src/seed-with-json-data-cli/readme.md)\n\n## references\n\n- http://www.postgresqltutorial.com/\n- http://www.postgres.cn/docs/9.6/\n- https://github.com/tgriesser/knex\n- http://knexjs.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdulin%2Fnodejs-pg-knex-samples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrdulin%2Fnodejs-pg-knex-samples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdulin%2Fnodejs-pg-knex-samples/lists"}