Skip to content

Commit 46c9b07

Browse files
committed
Update readme
1 parent 6b4abd4 commit 46c9b07

File tree

3 files changed

+19
-80
lines changed

3 files changed

+19
-80
lines changed

README.md

+19-72
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,46 @@
11
# postgres-schema-ts
22

3-
> postgres-schema-ts is a simple npm module you can use to convert a mysql schema into typescript interfaces
3+
> postgres-schema-ts is a simple npm module you can use to convert a postgres schema into typescript interfaces
44
55
# Usage
66

77
```bash
88
# to infer an entire schema
9-
$ npx postgres-schema-ts mysql://root@localhost:3306/database
9+
$ npx postgres-schema-ts postgresql://postgres@localhost:5433/db?currentSchema=public
1010

1111
# to infer a specific table
12-
$ npx postgres-schema-ts mysql://root@localhost:3306/database table_name
12+
$ npx postgres-schema-ts postgresql://postgres@localhost:5433/db?currentSchema=public table_name
1313
```
1414

1515
tip: You can pipe the output of postgres-schema-ts into a file with `npx postgres-schema-ts <args> > schema.ts`
1616

1717
## Demo
1818

19-
For the following SQL schema: (from the musicbrainz database)
19+
For the following SQL schema:
2020

2121
```sql
22-
CREATE TABLE IF NOT EXISTS artist ( -- replicate (verbose)
23-
id SERIAL,
24-
gid CHAR(36) NOT NULL,
25-
name VARCHAR(255) NOT NULL,
26-
sort_name VARCHAR(255) NOT NULL,
27-
begin_date_year SMALLINT,
28-
begin_date_month SMALLINT,
29-
begin_date_day SMALLINT,
30-
end_date_year SMALLINT,
31-
end_date_month SMALLINT,
32-
end_date_day SMALLINT,
33-
type INTEGER, -- references artist_type.id
34-
area INTEGER, -- references area.id
35-
gender INTEGER, -- references gender.id
36-
comment VARCHAR(255) NOT NULL DEFAULT '',
37-
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0),
38-
last_updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
39-
ended CHAR(1) NOT NULL DEFAULT FALSE
40-
);
41-
42-
CREATE TABLE IF NOT EXISTS track ( -- replicate (verbose)
43-
id SERIAL,
44-
gid CHAR(36) NOT NULL,
45-
recording INTEGER NOT NULL, -- references recording.id
46-
medium INTEGER NOT NULL, -- references medium.id
47-
position INTEGER NOT NULL,
48-
number TEXT NOT NULL,
49-
name VARCHAR(255) NOT NULL,
50-
artist_credit INTEGER NOT NULL, -- references artist_credit.id
51-
length INTEGER CHECK (length IS NULL OR length > 0),
52-
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0),
53-
last_updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
54-
is_data_track CHAR(1) NOT NULL DEFAULT FALSE
55-
) CHARACTER SET utf8 COLLATE utf8_general_ci;
22+
CREATE TABLE account (
23+
username VARCHAR (50) UNIQUE NOT NULL,
24+
password VARCHAR (50) NOT NULL,
25+
email VARCHAR (355) UNIQUE NOT NULL,
26+
created_on TIMESTAMP NOT NULL,
27+
last_login TIMESTAMP
28+
)
5629
```
5730

5831
run:
5932

6033
```bash
61-
$ npx postgres-schema-ts mysql://root@localhost:3306/musicbrainz
34+
$ npx postgres-schema-ts postgresql://postgres@localhost:5433/db?currentSchema=public
6235
```
6336

6437
```typescript
65-
export interface artist {
66-
id: number
67-
gid: string
68-
name: string
69-
sort_name: string
70-
begin_date_year: number | null
71-
begin_date_month: number | null
72-
begin_date_day: number | null
73-
end_date_year: number | null
74-
end_date_month: number | null
75-
end_date_day: number | null
76-
type: number | null
77-
area: number | null
78-
gender: number | null
79-
comment: string
80-
edits_pending: number
81-
last_updated: Date
82-
ended: string
83-
}
84-
export interface track {
85-
id: number
86-
gid: string
87-
recording: number
88-
medium: number
89-
position: number
90-
number_: string
91-
name: string
92-
artist_credit: number
93-
length: number | null
94-
edits_pending: number
95-
last_updated: Date
96-
is_data_track: string
38+
export interface account {
39+
username: string
40+
password: string
41+
email: string
42+
created_on: Date
43+
last_login: Date | null
9744
}
9845
```
9946

@@ -112,7 +59,7 @@ postgres-schema-ts is inpired by the awesome [schemats](https://github.com/Sweet
11259
But takes a simpler, more blunt, and configuration free approach:
11360

11461
- Simpler defaults
115-
- MySQL support only
62+
- Postgres support only
11663
- Inline enums
11764
- No support for namespaces
11865

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"devDependencies": {
5858
"@types/jest": "^24.0.23",
5959
"@types/lodash": "^4.14.149",
60-
"@types/mysql": "^2.15.8",
6160
"@types/node": "^12.12.14",
6261
"@types/prettier": "^1.19.0",
6362
"@typescript-eslint/eslint-plugin": "^2.10.0",

yarn.lock

-7
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,6 @@
425425
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
426426
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==
427427

428-
"@types/mysql@^2.15.8":
429-
version "2.15.8"
430-
resolved "https://registry.yarnpkg.com/@types/mysql/-/mysql-2.15.8.tgz#305172ee6ec530acd16a713f680dbfb4399960a8"
431-
integrity sha512-l0TUdg6KDEaLO75/yjdjksobJDRWv8iZlpRfv/WW1lQZCQDKdTDnKCkeH10oapzP/JTuKiTy6Cvq/sm/0GgcUw==
432-
dependencies:
433-
"@types/node" "*"
434-
435428
"@types/node@*", "@types/node@^12.12.14":
436429
version "12.12.18"
437430
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.18.tgz#8d16634797d63c2af5bc647ce879f8de20b56469"

0 commit comments

Comments
 (0)