Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Generate TypeScript type definitions from database schema.
npm install schema-typegen
For now only Postgres is supported.
Usage: schema-typegen [options] <connection>
Options:
-V, --version output the version number
-f, --suffix <suffix> suffix to append to generated table type, e.g. item -> ItemEntity (default: "Entity")
-s, --schema <schema> schema (default: "public")
-h, --header <header> header content (default: "")
-o, --output <output> file output path (default: "stdout")
-e, --exclude <exclude> excluded tables and enums as comma separated string e.g. knex_migrations,knex_migrations_lock (default: [])
--type use type definitions instead of interfaces in generated output (default: false)
--noSemi, --no-semicolons omit semicolons in generated types
--ssl use ssl (default: false)
--optionals use optionals "?" instead of null (default: false)
--pascal-enums transform enum keys to pascal case (default: false)
--bigint use bigint for int8 types instead of strings (default: false)
--date-as-string use string for date types instead of javascript Date object (default: false)
--help display help for command
Example:
$ schema-typegen -o ./entities.ts postgres://username:password@localhost:5432/database
Given database table
CREATE TYPE user_state AS ENUM (
'asleep',
'awake'
);
CREATE TABLE users (
id int4 NOT NULL,
name varchar(255),
state user_state,
is_enabled bool NOT NULL DEFAULT FALSE
);
Running schema-typegen -o ./entities.ts postgres://username:password@localhost:5432/database
Will generate the following type definitions
enum UserState {
asleep = 'asleep',
awake = 'awake'
}
interface UserEntity {
id: number;
name: string | null;
state: UserState | null;
is_enabled: boolean;
}
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 })
})()
export $(grep -v '^#' .env | xargs) && schema-typegen -o ./entities.ts postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME
schema-typegen -o ./entities.ts postgres://$(jq -r '.DB.USERNAME' config.json):$(jq -r '.DB.PASSWORD' config.json)@$(jq -r '.DB.HOST' config.json):$(jq -r '.DB.PORT' config.json)/$(jq -r '.DB.NAME' config.json)
docker-compose up -d
npm test
Contributions, issues and feature requests are welcome!
Copyright © 2020 Aldis Ameriks.
This project is MIT licensed.
FAQs
Postgres pubsub client
The npm package pg-notify receives a total of 1,558 weekly downloads. As such, pg-notify popularity was classified as popular.
We found that pg-notify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.