mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-22 12:19:09 +00:00
Initial commit to release
This commit is contained in:
69
packages/cli/src/Db.ts
Normal file
69
packages/cli/src/Db.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import {
|
||||
IDatabaseCollections,
|
||||
DatabaseType,
|
||||
} from './';
|
||||
|
||||
import {
|
||||
UserSettings,
|
||||
} from "n8n-core";
|
||||
|
||||
import {
|
||||
ConnectionOptions,
|
||||
createConnection,
|
||||
getRepository,
|
||||
} from "typeorm";
|
||||
|
||||
import * as config from 'config';
|
||||
|
||||
|
||||
import {
|
||||
MongoDb,
|
||||
SQLite,
|
||||
} from './db';
|
||||
|
||||
export let collections: IDatabaseCollections = {
|
||||
Credentials: null,
|
||||
Execution: null,
|
||||
Workflow: null,
|
||||
};
|
||||
|
||||
import * as path from 'path';
|
||||
|
||||
export async function init(): Promise<IDatabaseCollections> {
|
||||
const dbType = config.get('database.type') as DatabaseType;
|
||||
const n8nFolder = UserSettings.getUserN8nFolderPath();
|
||||
|
||||
let entities;
|
||||
let connectionOptions: ConnectionOptions;
|
||||
|
||||
if (dbType === 'mongodb') {
|
||||
entities = MongoDb;
|
||||
connectionOptions = {
|
||||
type: 'mongodb',
|
||||
url: config.get('database.mongodbConfig.url') as string,
|
||||
useNewUrlParser: true,
|
||||
};
|
||||
} else if (dbType === 'sqlite') {
|
||||
entities = SQLite;
|
||||
connectionOptions = {
|
||||
type: 'sqlite',
|
||||
database: path.join(n8nFolder, 'database.sqlite'),
|
||||
};
|
||||
} else {
|
||||
throw new Error(`The database "${dbType}" is currently not supported!`);
|
||||
}
|
||||
|
||||
Object.assign(connectionOptions, {
|
||||
entities: Object.values(entities),
|
||||
synchronize: true,
|
||||
logging: false
|
||||
});
|
||||
|
||||
await createConnection(connectionOptions);
|
||||
|
||||
collections.Credentials = getRepository(entities.CredentialsEntity);
|
||||
collections.Execution = getRepository(entities.ExecutionEntity);
|
||||
collections.Workflow = getRepository(entities.WorkflowEntity);
|
||||
|
||||
return collections;
|
||||
}
|
||||
Reference in New Issue
Block a user