sequelize#ModelType TypeScript Examples

The following examples show how to use sequelize#ModelType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sequelize.ts    From ucast with Apache License 2.0 6 votes vote down vote up
export function createInterpreter(interpreters: Record<string, SqlOperator<any>>) {
  const interpretSQL = createSqlInterpreter(interpreters);

  return (condition: Condition, Model: ModelType) => {
    const dialect = Model.sequelize!.getDialect() as keyof typeof dialects;
    const options = dialects[dialect];

    if (!options) {
      throw new Error(`Unsupported database dialect: ${dialect}`);
    }

    const [sql, params, joins] = interpretSQL(condition, options, Model);
    return {
      include: joins.map(association => ({ association, required: true })),
      where: literal(Utils.format([sql, ...(params as string[])], dialect)),
    };
  };
}
Example #2
Source File: sequelize.ts    From ucast with Apache License 2.0 5 votes vote down vote up
function joinRelation(relationName: string, Model: ModelType) {
  return Model.associations.hasOwnProperty(relationName);
}