How to use the DataSource function from typeorm
Find comprehensive JavaScript typeorm.DataSource code examples handpicked from public code repositorys.
GitHub: sogebot/sogeBot
![sogebot profile picture](/sogebot.png?size=40)
104 105 106 107 108 109 110 111 112 113
migrations: [ `dest/database/migration/sqlite/**/*.js` ], }; let AppDataSource; if (process.env.TYPEORM_AppDataSource === 'mysql' || process.env.TYPEORM_AppDataSource === 'mariadb') { AppDataSource = new DataSource(MySQLDataSourceOptions); } else if (process.env.TYPEORM_AppDataSource === 'postgres') { AppDataSource = new DataSource(PGDataSourceOptions); } else { AppDataSource = new DataSource(SQLiteDataSourceOptions);
+ 5 other calls in file
21 22 23 24 25 26
serialNumber: { type: 'varchar' }, passTypeId: { type: 'varchar' }, }, }); module.exports = new typeorm.DataSource(Object.assign({ entities: [passes, registrations] }, config.database));
+ 3 other calls in file
141 142 143 144 145 146 147 148 149 150
```javascript const { DataSource } = require('typeorm') const { User, Pet } = require('./my-module') module.exports = new DataSource({ type: 'sqlite', database: ':memory:', entities: [User, Pet], })
+ 9 other calls in file
55 56 57 58 59 60 61 62 63 64
```javascript const fastify = require('fastify'); const dbConn = require('typeorm-fastify-plugin'); const { DataSource } = require('typeorm'); const connection = new DataSource({ host: 'localhost', port: 3306, type: 'mysql', database: 'your_database_name',
+ 13 other calls in file
GitHub: DIY0R/medium
29 30 31 32 33 34
const typeorm_1 = require("typeorm"); const post_model_1 = __importStar(require("./models/post.model")); const user_model_1 = __importDefault(require("./models/user.model")); const sslparam_1 = require("./sslparam"); exports.DBCONNECTINFO = Object.assign({ type: "postgres", host: process.env.DB_HOST || "", port: process.env.DB_PORT || "", username: process.env.DB_USER || "", password: process.env.DB_PASSWORD || "", database: process.env.DB_NAME || "", synchronize: true, logging: true, entities: [post_model_1.default, user_model_1.default, post_model_1.LikePostModel, post_model_1.DislikePostModel], subscribers: [] }, (0, sslparam_1.sslparam)()); exports.myDataSource = new typeorm_1.DataSource(exports.DBCONNECTINFO);
+ 3 other calls in file
GitHub: midwayjs/midway
![midwayjs profile picture](/midwayjs.png?size=40)
28 29 30 31 32 33 34 35 36 37
dataSourceFileExports = dataSourceFileExports.dataSource[ dataSourceFileExports['defaultClientName'] || 'default' ]; return new DataSource(dataSourceFileExports); } else { console.log( '[midway:typeorm] Not found dataSource options and run origin loadDataSource method' );
GitHub: tohird03/Warehouse
23 24 25 26 27 28 29 30 31 32
}; Object.defineProperty(exports, "__esModule", { value: true }); exports.dataSource = void 0; const typeorm_1 = require("typeorm"); const path = __importStar(require("path")); exports.dataSource = new typeorm_1.DataSource({ type: 'postgres', host: 'warehouse.cdbklndprnum.us-east-2.rds.amazonaws.com', port: 5432, username: 'postgres',
5 6 7 8 9 10 11 12 13 14 15
const morgan = require("morgan"); const bcrypt = require("bcrypt"); const jwt = require("jsonwebtoken"); const { DataSource } = require("typeorm"); const database = new DataSource({ type: process.env.TYPEORM_CONNECTION, host: process.env.TYPEORM_HOST, port: process.env.TYPEORM_PORT, username: process.env.TYPEORM_USERNAME,
GitHub: baicie/pm2-web-test
161 162 163 164 165 166 167 168 169 170 171
User = __decorate2([ (0, import_typeorm2.Entity)() ], User); // server/utils/db/db.ts var connection = new import_typeorm3.DataSource({ type: "sqlite", database: "pm2-web", logging: false, entities: [
+ 30 other calls in file
33 34 35 36 37 38 39 40 41 42
Object.defineProperty(exports, "__esModule", { value: true }); exports.postgresInit = exports.postgres = void 0; const typeorm_1 = require("typeorm"); const config_1 = require("../../configs/config"); const entity = __importStar(require("../../entities")); const postgres = new typeorm_1.DataSource({ type: 'postgres', host: config_1.postgresConfig.host, port: +config_1.postgresConfig.port, username: config_1.postgresConfig.username,
+ 186 other calls in file
36 37 38 39 40 41 42 43 44 45
async initialize() { const config = await (0, helpers_1.loadConfig)('database'); const entities = await this.getEntities(); const modelEntities = (config.entities || []).map((schema) => new typeorm_1.EntitySchema(schema)); modelEntities.push(...entities); this.datasource = new typeorm_1.DataSource({ ...config, type: config.type, synchronize: true, logging: false,
45 46 47 48 49 50 51 52 53
*/ const ormconfig = ormconfigObject[process.env.NODE_ENV]; // console.log('ormconfig', ormconfig); exports.ormconfig = ormconfig; const dataSource = new DataSource(ormconfig); // console.log('dataSource', dataSource); exports.default = dataSource;
+ 276 other calls in file
17 18 19 20 21 22 23 24 25 26 27 28
}) // process.exit(0); })(); const dataSource = new typeorm.DataSource({ type: "mysql", host: "localhost", port: 3306, username: "root",
3 4 5 6 7 8 9 10 11 12 13
const cors = require('cors'); const morgan = require('morgan'); const { DataSource } = require('typeorm') const app = express(); const myDataSource = new DataSource({ type: process.env.DB_TYPE, host: process.env.DB_HOST, port: process.env.DB_PORT, username: process.env.DB_USERNAME,
3 4 5 6 7 8 9 10 11 12 13
const { getEntitySchemaList, getDatabasePath, } = require('./util.datasource.js'); const dataSource = new DataSource({ type: 'better-sqlite3', database: getDatabasePath(), synchronize: true, logging: false,
17 18 19 20 21 22 23 24 25 26
#dataSource; constructor(type, host, port, username, password, database, entities) { this.#connected = false; this.#initConn = false; this.#dataSource = new orm.DataSource({ type, host, port, username,
typeorm.getCustomRepository is the most popular function in typeorm (5799 examples)