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

added typeOverrides option #547

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

kurochin143
Copy link
Contributor

@kurochin143 kurochin143 commented Aug 7, 2021

Added option typeOverrides.
It allows overriding the field types of the generated class.
For my use case I had to change the type of the roles table column name to a custom enum type.
Current output

export interface RolesAttributes {
	name: string;
        description?: string;
}

export class Roles extends Model<RolesAttributes, RolesCreationAttributes> implements RolesAttributes {
	name!: string;
        description?: string;
}

New output

import { RoleNames } from '../RoleNames'; // adds import

export interface RolesAttributes {
	name: RoleNames; // changed type
        description?: string;
}

export class Roles extends Model<RolesAttributes, RolesCreationAttributes> implements RolesAttributes {
	name!: RoleNames;
        description?: string;
}

How to use

options
{
 typeOverrides: {
  tables: {
    roles: { // name of table in db
      name: { // name of column in db
        type: "RoleNames",
        source: "../RoleNames",
        isDefault: false,
        isOptional: false
    }
  }
 }
}
/**
 * @type Optional. Name of the type
 * @source Optional. File path of the type relative to file in the directory.
 *         Leave undefined if overriding with primitive types
 * @isDefault Optional. Whether the type is an export default. Default false
 * @isOptional Optional. Override optionality
 */

@kurochin143 kurochin143 changed the title Override the typeOverride option Aug 7, 2021
@kurochin143 kurochin143 changed the title typeOverride option added typeOverride option Aug 7, 2021
@kurochin143 kurochin143 changed the title added typeOverride option added typeOverrides option Aug 7, 2021
@kurochin143
Copy link
Contributor Author

More changes added.

Nullable columns will now be using null instead of ?

Current output

export interface RolesAttributes {
	name: string;
        description?: string;
}

export class Roles extends Model<RolesAttributes, RolesCreationAttributes> implements RolesAttributes {
	name!: string;
        description?: string;
}

New output

export interface RolesAttributes {
	name: string;
        description: string | null;
}

export class Roles extends Model<RolesAttributes, RolesCreationAttributes> implements RolesAttributes {
	name!: string;
        description!: string | null;
}

This is more logical since the value is actually a null rather than undefined.

@kurochin143
Copy link
Contributor Author

More changes added.

Controls the default type of nullable table column. This overrides the previous change of having null column as default. Enabling users to revert back to the current output.

Current output

export interface RolesAttributes {
	name: string;
        description?: string;
}

export class Roles extends Model<RolesAttributes, RolesCreationAttributes> implements RolesAttributes {
	name!: string;
        description?: string;
}

New output

export interface RolesAttributes {
	name: string;
        description?: string | null;
}

export class Roles extends Model<RolesAttributes, RolesCreationAttributes> implements RolesAttributes {
	name!: string;
        description?: string | null;
}

How to use

options
{
 typeOverrides: {
  nullableFieldType: "NULL_AND_OPTIONAL"
 }
}

@nullableFieldType use "NULL", "OPTIONAL", OR "NULL_AND_OPTIONAL" for nullable table columns. Default "NULL_AND_OPTIONAL"

@joaoe
Copy link
Contributor

joaoe commented Dec 14, 2021

typeOverrides: {
tables: {
roles: { // name of table in db
name: { // name of column in db

Can one use a DB schema with the table name, like "dbo.roles": { // ... ?

@Ngreene-mwks
Copy link

Any updates? This would fix an issue I have.

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

Successfully merging this pull request may close these issues.

None yet

4 participants