https://github.com/zweifisch/uddl
universal schema language
https://github.com/zweifisch/uddl
Last synced: 5 months ago
JSON representation
universal schema language
- Host: GitHub
- URL: https://github.com/zweifisch/uddl
- Owner: zweifisch
- Created: 2024-11-28T09:12:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-02T07:19:59.000Z (over 1 year ago)
- Last Synced: 2025-10-29T05:58:00.716Z (9 months ago)
- Language: TypeScript
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Universal Data Description Language
```
TypeScript <- UDDL -> SQL
|
v
json-schema
```
Example:
```
User {
id(primary_key auto_increment): int
name?: string
email(unique maxLength:255): string
gender(default:0 maximum:2): int
}
```
### -> TypeScript
```ts
import {toTS} from 'uddl'
toTS(input)
```
```ts
export class User {
id: number
name?: string
email: string
gender: number = 0
}
```
### -> SQL
```ts
import {toSQL} from 'uddl'
toSQL(input)
```
```sql
CREATE TABLE "user" (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
email TEXT UNIQUE NOT NULL,
gender INTEGER DEFAULT 0 NOT NULL
);
```
#### postgresql
```ts
toSQL(input, {flavor: 'postgresql'})
```
```sql
CREATE TABLE "user" (
id PRIMARY KEY BIGSERIAL,
name TEXT,
email VARCHAR(255) NOT NULL,
gender SMALLINT NOT NULL DEFAULT 0
);
```
### -> json-schema
```ts
import {toJSONSchema} from 'uddl'
toJSONSchema(input)
```
```json
{
"definitions": {
"User": {
"type": "object",
"properties": {
"email": {
"type": "string",
"maxLength": 255
},
"gender": {
"maximum": 2,
"type": "integer"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
},
"required": [ "id", "email", "gender" ]
}
}
}
```