Skip to content

Instantly share code, notes, and snippets.

@championswimmer
Last active January 19, 2018 22:51
Show Gist options
  • Save championswimmer/a852aae1b530ae4e0842c837afabd139 to your computer and use it in GitHub Desktop.
Save championswimmer/a852aae1b530ae4e0842c837afabd139 to your computer and use it in GitHub Desktop.
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