n8n项目node后端sqlite相关的

配置信息

packages\@n8n\config\src\configs\database.config.ts

javascript 复制代码
@Config
export class SqliteConfig {
	/** SQLite database file name */
	@Env('DB_SQLITE_DATABASE')
	database: string = 'database.sqlite';

	/** SQLite database pool size. Set to `0` to disable pooling. */
	@Env('DB_SQLITE_POOL_SIZE')
	poolSize: number = 0;

	/**
	 * Enable SQLite WAL mode.
	 */
	@Env('DB_SQLITE_ENABLE_WAL')
	enableWAL: boolean = this.poolSize > 1;

	/**
	 * Run `VACUUM` on startup to rebuild the database, reducing file size and optimizing indexes.
	 *
	 * @warning Long-running blocking operation that will increase startup time.
	 */
	@Env('DB_SQLITE_VACUUM_ON_STARTUP')
	executeVacuumOnStartup: boolean = false;
}

SQLite 数据库文件存储位置

C:\Users\用户名\.n8n\database.sqlite

构建连接选项

javascript 复制代码
	private getSqliteConnectionOptions(): SqliteConnectionOptions | SqlitePooledConnectionOptions {
		const { sqlite: sqliteConfig } = this.config;
		const { n8nFolder } = this.instanceSettingsConfig;

		const commonOptions = {
			...this.getCommonOptions(),
			database: path.resolve(n8nFolder, sqliteConfig.database),
			migrations: sqliteMigrations,
		};

		if (sqliteConfig.poolSize > 0) {
			return {
				type: 'sqlite-pooled',
				poolSize: sqliteConfig.poolSize,
				enableWAL: true,
				acquireTimeout: 60_000,
				destroyTimeout: 5_000,
				...commonOptions,
			};
		} else {
			return {
				type: 'sqlite',
				enableWAL: sqliteConfig.enableWAL,
				...commonOptions,
			};
		}
	}

初始化连接

packages\@n8n\db\src\connection\db-connection.ts

javascript 复制代码
	async init(): Promise<void> {
		const { connectionState, options } = this;
		if (connectionState.connected) return;
		try {
			await this.dataSource.initialize();
		} catch (e) {
			let error = ensureError(e);
			if (
				options.type === 'postgres' &&
				error.message === 'Connection terminated due to connection timeout'
			) {
				error = new DbConnectionTimeoutError({
					cause: error,
					configuredTimeoutInMs: options.connectTimeoutMS!,
				});
			}
			throw error;
		}

		if (
			(options.type === 'mysql' || options.type === 'mariadb') &&
			this.binaryDataConfig.availableModes.includes('database')
		) {
			const maxAllowedPacket = this.binaryDataConfig.dbMaxFileSize * 1024 * 1024;
			try {
				await this.dataSource.query(`SET GLOBAL max_allowed_packet = ${maxAllowedPacket}`);
			} catch {
				this.logger.warn(
					`Failed to set \`max_allowed_packet\` to ${maxAllowedPacket} bytes on your MySQL server. ` +
						`Please set \`max_allowed_packet\` to at least ${this.binaryDataConfig.dbMaxFileSize} MiB in your MySQL server configuration.`,
				);
			}
		}

		connectionState.connected = true;
		if (!inTest) this.scheduleNextPing();
	}

直接修改数据库的值

参考链接

https://typeorm.io/docs/getting-started

https://typeorm.bootcss.com/

相关推荐
阿丰资源15 小时前
java项目(附资料)-基于SpringBoot+MyBatisPlus+MySQL+Layui的药品管理系统
java·spring boot·mysql
云恒要逆袭15 小时前
Java SE、EE、ME到底啥区别?我被这个问题困扰了一整年
java·java ee
一叶飘零_sweeeet15 小时前
击穿 MySQL 性能天花板:InnoDB Buffer Pool 核心架构、LRU 优化与生产调优全解
数据库·mysql
鱼鳞_15 小时前
Java学习笔记_Day27(Stream流)
java·笔记·学习
身如柳絮随风扬15 小时前
Servlet:访问流程、核心接口与生命周期
java·servlet·web
indexsunny15 小时前
互联网大厂Java面试实战:从Spring Boot到微服务架构的深度探讨
java·数据库·spring boot·安全·微服务·监控·面试实战
一叶飘零_sweeeet15 小时前
MySQL InnoDB 锁机制全解:行锁 / 表锁 / 间隙锁 / 临键锁底层逻辑与死锁避坑指南
数据库·mysql
wgzrmlrm7415 小时前
如何从SQL中提取年份或月份:EXTRACT与日期函数用法
jvm·数据库·python
夕除15 小时前
javaweb--03
java
D4c-lovetrain15 小时前
linux个人心得23 (mysql②)
数据库·mysql