{"dist":{"shasum":"75446b0ee401a325bf180813bba59dc40fca1486","tarball":"https://registry.npmjs.org/prisma-db-introspection/-/prisma-db-introspection-1.35.0-alpha.2.tgz","fileCount":216,"integrity":"sha512-S2LdRBWKO0TI+aFAfe77En8PoMxAljprIToV/f35Snz4n3Bz5KKpF8t68xJdG9hUoHbfcivJrlRW6ONDVZTlWA==","signatures":[{"sig":"MEYCIQCiqcD40tdJusPBs5AvRBJDJm5AHmYtVU/3/qKHDxfTEwIhAIVw2juJY0o6rTC/kZuEQs4eCI21K8f1j64STJzuSrnp","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1236311,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc7TgBCRA9TVsSAnZWagAAAq0P/RKado1sgqgTGmfZ8qQD\nWvfkQ/3ldr2z+wTsdxNltGtlIHc6mjgdsr+wfaGFB93IuyV5aQ12PplRNAXE\nIKTNIwFMi/LGbpLt9NucRNZWG1Sh90SihiLjRKOX+ocqIlobcX78Lv1zcZNo\nTnKccvsO1DV8bbAaMLzqxW7uu19DKXR1RTEUgQ++DRPDTI6sk9AoA7NERoGM\nFCH8jHBkhFUsmUDOFdfM+iGezR406DxV2RmDYwWPeti164B4nNsoC8eSs/vU\n+25BMMymuZrP7lTTKRoj6uYPstLXQ2YtCRrpz+nCPUGCepOmLtPLstHR3Pbi\nyYlge5H21R/juGtzrzdc3H7JgzJHlunRCIqQas+bXHyIyjNzpw5r9bub3TA1\nwGHCfuEENl4p1qa6/c8rFW/JoxkU6lMBeHj5Ewbdr+BaCpx39JaHR5Pf/iwz\nJLon3Kac+HyC4BiVoDIiz9FEv7NEPdkc9Tz35kFJFFNzukS90alMXkDlRs6r\n2n6BJHpKgWB6ZWp+gG4lReXSWvjzrktlPdqZAR940VPFekMoMrCWZ3tDv4qM\nW2Z3TwijOA6biJKMK7U3HFZ0M+fs1jFexiSKqAS+/RZC1aZ/qVZM2U11PHuu\nFbDQDlUpFVxYO+xIKKOr0CYf20ZDcy6tJBxv1in3Bg6gvUEdhLgD2Uk6fgS1\nVAQU\r\n=EEwe\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"testRegex":"(src/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$","transform":{"^.+\\.tsx?$":"ts-jest"},"moduleFileExtensions":["ts","tsx","js","jsx","json","node"],"testPathIgnorePatterns":["/node_modules/","helpers.ts","connectionDetails.ts","common.ts","/data/","dist"]},"main":"dist/index.js","name":"prisma-db-introspection","types":"dist/index.d.ts","readme":"# prisma-db-introspection\n\nThis module is capable of generating a prisma datamodel for a relational or document databases. Please refer to the `prisma-datamodel` doc for more information on the `ISDL` datamodel structure.\n\n## Convenient Shorthand usage \n\nIintrospection and rendering in one step):\n\n```typescript\nconst renderedSdl = await connector.introspect(schema).renderToNormalizdDatamodelString()\n```\n\nCreating a connector: \n\n```typescript\nconst connector = Connectors.create(DatabaseType.mysql, client)\nconst connector = Connectors.create(DatabaseType.postgres, client)\nconst connector = Connectors.create(DatabaseType.mongo, client)\n```\n\nThe database client has to be connected and disconnected by the caller. Please refer to the connector implementation to see the required client library.\n\n## Detailed Usage \n\nIntrospect the database:\n```typescript\nconst introspection = await connector.introspect(schema)\n```\n\nThe introspection result caches all database related information and is database specific.\n\nCreate an `ISDL` structure from the introspection:\n\n```typescript\nconst sdl: ISDL = await introspection.getNormalizedDatamodel()\n```\n\nor with an existing reference model:\n```typescript\nconst sdl: ISDL = await introspection.getNormalizedDatamodel(referenceModel)\n```\n\nit is also possible to get an unnormalized datamodel, basically a raw introspection result from the database. The unnormalized model is most likely not a valid datamodel.\n\n```typescript\nconst sdl: ISDL = await introspection.getDatamodel() // Don't use unless you know what you're doing\n```\n\nRendering can be done using `prisma-datamodel`.\n\nWith prototype features enabled (V1.1):\n\n```typescript\nconst renderer = Renderers.create(introspection.databaseType, true)\nconst renderedSdl = renderer.render(sdl)\n```\n\nWithout prototype features, simply use the shorthand:\n```typescript\nconst renderer = Renderers.create(introspection.databaseType)\nconst renderedSdl = renderer.render(sdl)\n```\nWhich is equivalent to, given the database type for rendering and introspection are the same:\n\n```typescript\nconst renderedSdl = introspection.renderToDatamodelString()\n```\n\nOr with an existing reference model:\n\n```typescript\nconst renderedSdl = introspection.renderToNormalizedDatamodelString(referenceModel)\n```\n\n### Document Database Introspection Internals\n\nDocument database introspection works by randomly sampling objects from each collection, inferring a schema for each object and merging these object schemas together. This is done in the class `ModelSampler`.\n\nFor each field which might be a reference to another collection, we attempt to look up objects in other collections by their primary key. If we find enough referred objects, we mark the field as relation. This is done in `RelationResolver`, and can be a somewhat expensive operation.\n\nThis approach should work for all forms of document DBs. The `MongoConnector` class can be used as a reference implementation.\n\n### Relational Database Introspection Internals\n\nRelational introspection works by querying the database schema using SQL, and then bringing everything together. \n\nRelations are resolved via their corresponding FK constraints, IDs are resolved via their corresponding PK constraints. \n\nHere, `MysqlConnector` , `MySqlIntrospectionResult` , `PostgresConnector` and `PostgresIntrospectionResult` can serve as a reference. \n\nThere is a common base class, `RelationalConnector` which attempts to unify certain queries using the `information_schema` table, which should be standardized. This approach had limited success in practice. \n\n### Normalization Pipeline\n\nThe exact normalization pipeline can be found in the `DefaultNormalizer` factory class. In the most complex case, introspecting a relational database with an existing base model, the following steps are applied:\n\n1. Copy Enum definitions from the existing base model.\n2. Remove all relation names which are not needed, unless they are explicitly given by the base model.\n3. Normalize all type and field names. If the type or field is present in the base model, copy the name and directives, as they might be known to prisma, but not to the database.\n4. Re-order all models according to the base model. For new types and enums, order alphabetically.\n5. Hide all reserved fields, like `updatedAt`, `createdAt`, `id`, unless they are present in the base model.\n6. Adjust the cardinality of relations which use a join table according to the base model, since we cannot guess them from the database.\n7. Remove all back relations for inine relations, except they are given in the datamodel. This is especially important for self-relations, which would otherwise generate duplicated fields.","license":"Apache-2.0","scripts":{"lint":"tslint src/**/*.ts","test":"jest --runInBand --verbose=false","build":"tsc -d","precommit":"lint-staged","prepublishOnly":"yarn build"},"_npmUser":{"name":"timsuchanek","email":"tim.suchanek@gmail.com"},"repository":{"url":"https://github.com/graphcool/graphcool/tree/prisma-cli/cli/packages/prisma-db-introspection"},"_npmVersion":"6.4.1","description":"This module is capable of generating a prisma datamodel for a relational or document databases. Please refer to the `prisma-datamodel` doc for more information on the `ISDL` datamodel structure.","directories":{},"maintainers":[{"name":"timsuchanek","email":"tim.suchanek@gmail.com"}],"_nodeVersion":"8.16.0","dependencies":{"pg":"^7.4.1","mysql":"^2.16.0","scuid":"^1.0.2","lodash":"^4.17.4","mongodb":"^3.1.10","pluralize":"^7.0.0","prisma-yml":"1.35.0-alpha.2","@types/mysql":"^2.15.5","@types/mongodb":"^3.1.14","graphql-request":"^1.5.0","prisma-datamodel":"1.35.0-alpha.2"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"23.6.0","tslint":"^5.6.0","ts-jest":"^23.10.5","prettier":"1.14.3","@types/pg":"^7.4.6","typescript":"^3.2.2","@types/jest":"^23.3.9","@types/node":"^8.0.57","@types/fs-extra":"^5.0.0","mongodb-memory-server-global":"^5.1.0"},"_npmOperationalInternal":{"tmp":"tmp/prisma-db-introspection_1.35.0-alpha.2_1559050240531_0.6894273521215826","host":"s3://npm-registry-packages"},"_id":"prisma-db-introspection@1.35.0-alpha.2","version":"1.35.0-alpha.2"}