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/

相关推荐
r***99821 小时前
【JAVA进阶篇教学】第十一篇:Java中ReentrantLock锁讲解
java·开发语言
宠..1 小时前
创建标签控件
java·服务器·开发语言·前端·c++·qt
-大头.1 小时前
Spring Boot CLI 从入门到企业级实战(上下篇)
java·spring boot·后端
一点事1 小时前
oracle:创建表空间、用户和授权
数据库·oracle
小二·1 小时前
Java基础教程之JDBC
java·开发语言
w***74401 小时前
使用python进行PostgreSQL 数据库连接
数据库·python·postgresql
yuuki2332331 小时前
【C++】类和对象(中)
android·java·c++·后端
hhwyqwqhhwy1 小时前
【无标题】
数据库
小白hemu1 小时前
Ubuntu24.04.3LTS+5090显卡驱动安装解决黑屏问题
数据库