-
-
Save championswimmer/a852aae1b530ae4e0842c837afabd139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {DefineAttributes, Instance, Model} from 'sequelize' | |
import * as Sequelize from 'sequelize' | |
// This is signature of my 'Client' objects | |
// Whenever I create 'Client' rows, the objects will be of this type | |
export interface ClientAttributes { | |
id: number, | |
secret: string, | |
whitelist_domains: string[], | |
whitelist_ips: string[], | |
redirect_url: string[] | |
} | |
// To define Client in db, the columns must be one of the | |
// keys of 'ClientAttributes', hence (( in keyof ClientAttributes )) | |
type ClientDefineAttributes = { | |
[x in keyof ClientAttributes]: string | DataTypeAbstract | DefineAttributeColumnOptions | |
} | |
// When writing this, I cannot stray away from **having to** | |
// use keys as in 'ClientAttributes' | |
// In Webstorm/VSCode I get autocomplete too | |
export const clientAttrs: ClientDefineAttributes = { | |
id: { | |
type: Sequelize.INTEGER, | |
primaryKey: true, | |
autoIncrement: true | |
}, | |
secret: Sequelize.STRING(32), | |
whitelist_domains: Sequelize.ARRAY(Sequelize.STRING), | |
whitelist_ips: Sequelize.ARRAY(Sequelize.STRING), | |
redirect_url: Sequelize.STRING | |
} | |
export interface ClientInstance extends Instance<ClientAttributes> { | |
get(): ClientAttributes | |
} | |
export interface Client extends Model<ClientInstance, ClientAttributes> { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment