schema-typegen
Advanced tools
Comparing version 2.4.0 to 2.5.0
{ | ||
"name": "schema-typegen", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "Generate TypeScript type definitions from database schema", | ||
"main": "schema-typegen.js", | ||
"types": "schema-typegen.d.ts", | ||
"bin": { | ||
@@ -7,0 +8,0 @@ "schema-typegen": "schema-typegen.js" |
@@ -99,2 +99,13 @@ <h1 align="center">Welcome to schema-typegen 👋</h1> | ||
### Running from code | ||
```ts | ||
import { join } from 'path' | ||
import generate from 'schema-typegen' | ||
;(async () => { | ||
const output = join(__dirname, 'entities.ts') | ||
await generate({ connection: 'postgres://username:password@localhost:5432/database', output }) | ||
})() | ||
``` | ||
### Loading database config | ||
@@ -101,0 +112,0 @@ |
@@ -63,2 +63,14 @@ #! /usr/bin/env node | ||
async function generateSchema (opts) { | ||
opts = { ...defaultOpts, exclude: [], ...opts } | ||
const schema = await postgres(opts) | ||
const types = await typescript(opts, schema) | ||
if (opts.output) { | ||
fs.writeFileSync(opts.output, types) | ||
return `✔ Generated types from ${schema.tables.length} tables and ${schema.enums.length} enums` | ||
} else { | ||
return types | ||
} | ||
} | ||
if (require.main === module) { | ||
@@ -73,16 +85,7 @@ (async () => { | ||
const schema = await postgres(opts) | ||
const types = await typescript(opts, schema) | ||
if (opts.output) { | ||
fs.writeFileSync(opts.output, types) | ||
console.log(`✔ Generated types from ${schema.tables.length} tables and ${schema.enums.length} enums`) | ||
} else { | ||
console.log(types) | ||
} | ||
const result = await generateSchema(opts) | ||
console.log(result) | ||
})() | ||
} | ||
module.exports = { | ||
typescript, | ||
postgres | ||
} | ||
module.exports = generateSchema |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15074
8
253
139