Home / File/ enforce-delete-with-where.ts — drizzle-orm Source File

enforce-delete-with-where.ts — drizzle-orm Source File

Architecture documentation for enforce-delete-with-where.ts, a typescript file in the drizzle-orm codebase. 5 imports, 2 dependents.

File typescript DrizzleORM QueryBuilders 5 imports 2 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  f0c93e37_d0c6_85de_9c85_875c07d8cd5b["enforce-delete-with-where.ts"]
  e5742924_3949_00fb_8a61_51fa28a972cf["ast.ts"]
  f0c93e37_d0c6_85de_9c85_875c07d8cd5b --> e5742924_3949_00fb_8a61_51fa28a972cf
  7089b0f7_fb5d_1f9c_807f_239903f9a3f3["resolveMemberExpressionPath"]
  f0c93e37_d0c6_85de_9c85_875c07d8cd5b --> 7089b0f7_fb5d_1f9c_807f_239903f9a3f3
  73e2aa44_a4c6_8ec0_4c1d_1b146021dedc["options.ts"]
  f0c93e37_d0c6_85de_9c85_875c07d8cd5b --> 73e2aa44_a4c6_8ec0_4c1d_1b146021dedc
  a580025e_b3a5_ddc6_91a8_9e031d9d7cf0["isDrizzleObj"]
  f0c93e37_d0c6_85de_9c85_875c07d8cd5b --> a580025e_b3a5_ddc6_91a8_9e031d9d7cf0
  02888e0e_5ac9_200a_278f_c729b5af7410["utils"]
  f0c93e37_d0c6_85de_9c85_875c07d8cd5b --> 02888e0e_5ac9_200a_278f_c729b5af7410
  ccb38674_a025_897a_eb29_bdfa2dbe01c1["index.ts"]
  ccb38674_a025_897a_eb29_bdfa2dbe01c1 --> f0c93e37_d0c6_85de_9c85_875c07d8cd5b
  9c5ab94d_585e_34b8_0ffe_d1b15f997374["delete.test.ts"]
  9c5ab94d_585e_34b8_0ffe_d1b15f997374 --> f0c93e37_d0c6_85de_9c85_875c07d8cd5b
  style f0c93e37_d0c6_85de_9c85_875c07d8cd5b 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 = 'enforceDeleteWithWhere';

let lastNodeName: string = '';

const deleteRule = createRule<Options, MessageIds>({
	defaultOptions: [{ drizzleObjectName: [] }],
	name: 'enforce-delete-with-where',
	meta: {
		type: 'problem',
		docs: {
			description: 'Enforce that `delete` method is used with `where` to avoid deleting all the rows in a table.',
		},
		fixable: 'code',
		messages: {
			enforceDeleteWithWhere:
				"Without `.where(...)` you will delete all the rows in a table. If you didn't want to do it, please use `{{ drizzleObjName }}.delete(...).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 (node.property.name === 'delete' && lastNodeName !== 'where' && isDrizzleObj(node, options)) {
						context.report({
							node,
							messageId: 'enforceDeleteWithWhere',
							data: {
								drizzleObjName: resolveMemberExpressionPath(node),
							},
						});
					}
					lastNodeName = node.property.name;
				}
				return;
			},
		};
	},
});

export default deleteRule;

Domain

Subdomains

Types

Frequently Asked Questions

What does enforce-delete-with-where.ts do?
enforce-delete-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-delete-with-where.ts?
enforce-delete-with-where.ts defines 2 function(s): createRule, deleteRule.create.
What does enforce-delete-with-where.ts depend on?
enforce-delete-with-where.ts imports 5 module(s): ast.ts, isDrizzleObj, options.ts, resolveMemberExpressionPath, utils.
What files import enforce-delete-with-where.ts?
enforce-delete-with-where.ts is imported by 2 file(s): delete.test.ts, index.ts.
Where is enforce-delete-with-where.ts in the architecture?
enforce-delete-with-where.ts is located at eslint-plugin-drizzle/src/enforce-delete-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