enforce-update-with-where.ts — drizzle-orm Source File
Architecture documentation for enforce-update-with-where.ts, a typescript file in the drizzle-orm codebase. 5 imports, 2 dependents.
Entity Profile
Dependency Diagram
graph LR 293f011b_cdb8_71ff_a37a_bbe21603eeb7["enforce-update-with-where.ts"] e5742924_3949_00fb_8a61_51fa28a972cf["ast.ts"] 293f011b_cdb8_71ff_a37a_bbe21603eeb7 --> e5742924_3949_00fb_8a61_51fa28a972cf 7089b0f7_fb5d_1f9c_807f_239903f9a3f3["resolveMemberExpressionPath"] 293f011b_cdb8_71ff_a37a_bbe21603eeb7 --> 7089b0f7_fb5d_1f9c_807f_239903f9a3f3 73e2aa44_a4c6_8ec0_4c1d_1b146021dedc["options.ts"] 293f011b_cdb8_71ff_a37a_bbe21603eeb7 --> 73e2aa44_a4c6_8ec0_4c1d_1b146021dedc a580025e_b3a5_ddc6_91a8_9e031d9d7cf0["isDrizzleObj"] 293f011b_cdb8_71ff_a37a_bbe21603eeb7 --> a580025e_b3a5_ddc6_91a8_9e031d9d7cf0 02888e0e_5ac9_200a_278f_c729b5af7410["utils"] 293f011b_cdb8_71ff_a37a_bbe21603eeb7 --> 02888e0e_5ac9_200a_278f_c729b5af7410 ccb38674_a025_897a_eb29_bdfa2dbe01c1["index.ts"] ccb38674_a025_897a_eb29_bdfa2dbe01c1 --> 293f011b_cdb8_71ff_a37a_bbe21603eeb7 879aed6e_90ff_5435_e0c6_ac2eb984dbb3["update.test.ts"] 879aed6e_90ff_5435_e0c6_ac2eb984dbb3 --> 293f011b_cdb8_71ff_a37a_bbe21603eeb7 style 293f011b_cdb8_71ff_a37a_bbe21603eeb7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { ESLintUtils } from '@typescript-eslint/utils';
import { resolveMemberExpressionPath } from './utils/ast';
import { isDrizzleObj, type Options } from './utils/options';
const createRule = ESLintUtils.RuleCreator(() => 'https://github.com/drizzle-team/eslint-plugin-drizzle');
type MessageIds = 'enforceUpdateWithWhere';
let lastNodeName: string = '';
const updateRule = createRule<Options, MessageIds>({
defaultOptions: [{ drizzleObjectName: [] }],
name: 'enforce-update-with-where',
meta: {
type: 'problem',
docs: {
description: 'Enforce that `update` method is used with `where` to avoid deleting all the rows in a table.',
},
fixable: 'code',
messages: {
enforceUpdateWithWhere:
"Without `.where(...)` you will update all the rows in a table. If you didn't want to do it, please use `{{ drizzleObjName }}.update(...).set(...).where(...)` instead. Otherwise you can ignore this rule here",
},
schema: [{
type: 'object',
properties: {
drizzleObjectName: {
type: ['string', 'array'],
},
},
additionalProperties: false,
}],
},
create(context, options) {
return {
MemberExpression: (node) => {
if (node.property.type === 'Identifier') {
if (
lastNodeName !== 'where'
&& node.property.name === 'set'
&& node.object.type === 'CallExpression'
&& node.object.callee.type === 'MemberExpression'
&& node.object.callee.property.type === 'Identifier'
&& node.object.callee.property.name === 'update'
&& isDrizzleObj(node.object.callee, options)
) {
context.report({
node,
messageId: 'enforceUpdateWithWhere',
data: {
drizzleObjName: resolveMemberExpressionPath(node.object.callee),
},
});
}
lastNodeName = node.property.name;
}
return;
},
};
},
});
export default updateRule;
Domain
Subdomains
Functions
Types
Dependencies
Source
Frequently Asked Questions
What does enforce-update-with-where.ts do?
enforce-update-with-where.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, QueryBuilders subdomain.
What functions are defined in enforce-update-with-where.ts?
enforce-update-with-where.ts defines 2 function(s): createRule, updateRule.create.
What does enforce-update-with-where.ts depend on?
enforce-update-with-where.ts imports 5 module(s): ast.ts, isDrizzleObj, options.ts, resolveMemberExpressionPath, utils.
What files import enforce-update-with-where.ts?
enforce-update-with-where.ts is imported by 2 file(s): index.ts, update.test.ts.
Where is enforce-update-with-where.ts in the architecture?
enforce-update-with-where.ts is located at eslint-plugin-drizzle/src/enforce-update-with-where.ts (domain: DrizzleORM, subdomain: QueryBuilders, directory: eslint-plugin-drizzle/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free