Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neat tool - why use namespaces? just curious #114

Open
ORESoftware opened this issue Feb 24, 2020 · 1 comment
Open

neat tool - why use namespaces? just curious #114

ORESoftware opened this issue Feb 24, 2020 · 1 comment

Comments

@ORESoftware
Copy link

This worked fine for me so far. Just curious why the use for namespaces?

when I ran this:

schemats generate -c 'postgres://postgres:postgres@localhost/postgres' -t 'user_table' -o schemas/user.ts

I got:

export namespace user_tableFields {
    export type id = number;
    export type handle = string;
    export type email = string;
    export type first_name = string;
    export type last_name = string;
    export type is_verified = boolean;

}

export interface user_table {
    id: user_tableFields.id;
    handle: user_tableFields.handle;
    email: user_tableFields.email;
    first_name: user_tableFields.first_name;
    last_name: user_tableFields.last_name;
    is_verified: user_tableFields.is_verified;

}
@HoldYourWaffle
Copy link

HoldYourWaffle commented Feb 24, 2020

Because it enables you to reference column types:

export namespace user_tableFields {
    export type id = number;
    ...
}

export namespace post_tableFields {
    export type id = number;
    ...
}

export interface MyUser {
    id: user_tableFields.id;
    posts: post_tableFields.id[];
}

I haven't used this library in a while and this isn't a very pretty example, but I hope it can clear up some confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants