{"id":25652993,"url":"https://github.com/path-check/safeplaces-data-layer","last_synced_at":"2025-04-16T02:51:25.496Z","repository":{"id":43935741,"uuid":"272805382","full_name":"Path-Check/safeplaces-data-layer","owner":"Path-Check","description":"Safe Places data layer is an external dependency library that handles the management of the database layer for the API, Ingest, and Translation API's.","archived":false,"fork":false,"pushed_at":"2023-01-11T03:05:45.000Z","size":1209,"stargazers_count":3,"open_issues_count":13,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-23T19:24:34.264Z","etag":null,"topics":["database","helper","non-critical","postgres"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Path-Check.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-16T20:26:09.000Z","updated_at":"2021-06-03T19:18:28.000Z","dependencies_parsed_at":"2023-02-09T00:17:33.284Z","dependency_job_id":null,"html_url":"https://github.com/Path-Check/safeplaces-data-layer","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Path-Check%2Fsafeplaces-data-layer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Path-Check%2Fsafeplaces-data-layer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Path-Check%2Fsafeplaces-data-layer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Path-Check%2Fsafeplaces-data-layer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Path-Check","download_url":"https://codeload.github.com/Path-Check/safeplaces-data-layer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249187029,"owners_count":21226839,"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":["database","helper","non-critical","postgres"],"created_at":"2025-02-23T19:18:41.667Z","updated_at":"2025-04-16T02:51:25.469Z","avatar_url":"https://github.com/Path-Check.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Safeplaces Data Layer Library\n\nThe Safeplaces Data layer is a sample library. It contains migrations, seeds, and the general schema for working with both the public and private libs.\n\nUnder the hood this utilizes the Knex library. So all services can access the standard Knex commands. More below.\n\nThe Safeplaces Backend deploys two different types of databases. One is public facing and the other is private. The reasons for this is a security concern that was identified early on. We don't want the published (redacted) data being stored in the same place as the ingested data. Additionally, we don’t want to be writing data from the public endpoints to the private database.\n\n## Environment Variables\n\nThe config is currently pre-setup for you so all you need to do is provide the correct environment variables.\n\n```\nDB_HOST=localhost\nDB_PASS=password\nDB_USER=safepaths\nDB_NAME=safepaths\n\nDB_HOST_PUB=localhost\nDB_PASS_PUB=password\nDB_USER_PUB=safepaths\nDB_NAME_PUB=safepaths_public\n\n```\n\n## Installation and Usage\n\nInstall by enter one of the commands below.\n\n```\nnpm install @pathcheck/data-layer\n\n-or-\n\nyarn add @pathcheck/data-layer\n```\n\nOnce installed, include it\n\n```\nconst db = require('@pathcheck/data-layer');\n\n// Pull the Organization Service from the Private database\nconst { organizationService } = db.private\n\norganizationService.all().then(data =\u003e console.log('All Data: ', data))\n\n// Pull the Access Codes Service from the Public database\nconst { pointService } = db.public\n\npointService.all().then(data =\u003e console.log('All Data: ', data))\n\n```\n\n### Knex\n\nTo access any of the knex commands, you can simply\n\n```\nconst db = require('@sublet/data-layer');\n\n// Pull the Organization Service from the Private database\nconst { organizationService } = db.private\n\norganizationService.table.insert({ name: 'Hello Name' }).returning('*')\n  .then(data =\u003e console.log('Data: ', data))\n\norganizationService.table.where({ id: 1 }).first()\n  .then(data =\u003e console.log('Data: ', data))\n\n```\n\n### Knex Helper Commands\n\nAdditionally, we have added some helper commands.\n\n```\nconst db = require('@sublet/data-layer');\n\n// Pull the Organization Service from the Private database\nconst { organizationService } = db.private\n\n// Returns all rows\norganizationService.all()\n\n// Returns all rows\norganizationService.updateOne(1, { name: 'Some other Name' })\n\n```\n\n## CLI\n\nDue to the nature of database management we have built in a small CLI that will allow you to run seeds and migrations. To install enter the following.\n\nThis needs to be installed globaly so run the following command.\n\n`npm i -g @pathcheck/data-layer`\n\n### Migrations\n\nUpdate the `PRIVATE` database with the most recent migrations in the development environment.\n\n`spdl migrate:latest --scope private --env development`\n\nUpdate the `PUBLIC` database with the most recent migrations in the development environment.\n\n`spdl migrate:latest --scope public --env test`\n\nRollback the public database\n\n`spdl migrate:rollback --scope public`\n\n### Seeds\n\nSeed the `PRIVATE` database with the correct seed files in the development environment.\n\n`spdl seed:run --scope private --env development`\n\nSeed the `PUBLIC` database with the correct seed files in the test environment.\n\n`spdl seed:run --scope public --env test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpath-check%2Fsafeplaces-data-layer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpath-check%2Fsafeplaces-data-layer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpath-check%2Fsafeplaces-data-layer/lists"}