How to use the createConnection function from typeorm

Find comprehensive JavaScript typeorm.createConnection code examples handpicked from public code repositorys.

376
377
378
379
380
381
382
383
384
385
386
    connectionSettings.username = process.env.TYPEORM_USERNAME;
    connectionSettings.password = process.env.TYPEORM_PASSWORD;
    connectionSettings.database = process.env.TYPEORM_DATABASE;
  }


  typeorm.createConnection(connectionSettings).then((connection) => {
    console.log(logSymbols.success, "Successfully connected to Database!");
    start();
  });
}
fork icon76
star icon377
watch icon0

14
15
16
17
18
19
20
21
22
23
  synchronize: false,
  migrationsRun: false,
  dropSchema: false,
  logging: false,
}
const rootConnection = await createConnection({ ...config })
const rootQueryRunner = rootConnection.createQueryRunner()
const database = 'graphql_typeorm_schema'
try {
  // TypeORM doesn't currently have a way to dump an SQL schema without any database interaction[1],
fork icon7
star icon38
watch icon9

+ 3 other calls in file

63
64
65
66
67
68
69
70
71
72
  t.strictEqual(fastify.orm.con1.name, 'default')
  await fastify.close()
})

test('custom client', async t => {
  const connection = await createConnection({
    host: 'localhost',
    type: 'postgres',
    port: '5432',
    password: '',
fork icon6
star icon23
watch icon6

+ 31 other calls in file

8
9
10
11
12
13
14
15
16

let connection
if (options.connection) {
  connection = options.connection
} else if (Object.keys(options).length) {
  connection = await createConnection(options)
} else {
  connection = await createConnection()
}
fork icon6
star icon23
watch icon0

+ 27 other calls in file

2
3
4
5
6
7
8
9
10
11
const ormconfig = require('../../ormconfig');
const { createConnection } = require('typeorm');

describe('Auth 테스트', () => {
        beforeAll(async () => {
                await createConnection(ormconfig);
                await request(app).post('/api/auth/signup').send({
                        userName: 'auth-test',
                        userEmail: 'test@naver.com',
                        userPassword: 'test123test123'
fork icon4
star icon16
watch icon3

+ 15 other calls in file

100
101
102
103
104
105
106
107
108
109
    database: 'osjsv3',
    synchronize: true,
    entities: [UserSchema]
  }, options);

  return createConnection(settings);
};

module.exports = {
  User,
fork icon4
star icon3
watch icon3

+ 9 other calls in file

73
74
75
76
77
78
79
80
81
82
if (!initialJWT) {
  console.error(`Usage ${process.argv0} {JWT}`)
  process.exit(1)
}

const typeormConnection = await typeorm.createConnection(typeormConfig)
const storage = new JolocomTypeormStorage(typeormConnection)
const passwordStore = new FilePasswordStore(__dirname+'/password.txt')

console.log('About to create JolocomSDK instance')
fork icon4
star icon3
watch icon17

+ 13 other calls in file

60
61
62
63
64
65
66
67
68
69

const type = process.env.TO.includes("://") ? process.env.TO.split(":")[0]?.replace("+srv", "") : "sqlite";
const isSqlite = type.includes("sqlite");

// @ts-ignore
const newDB = await createConnection({
	type,
	url: isSqlite ? undefined : process.env.TO,
	database: isSqlite ? process.env.TO : undefined,
	entities,
fork icon0
star icon1
watch icon1

87
88
89
90
91
92
93
94
95
96
//     }
// });
// 
// const upload = multer({ storage: storage });
// 
// const connection = createConnection({
//     type: 'mysql',
//     host: 'localhost',
//     port: 3306,
//     username: 'root',
fork icon0
star icon1
watch icon0

90
91
92
93
94
95
96
97
98
99

const entities = modelsLoader({}, { register: false })

if (projectConfig.database_type === "sqlite") {
  connectionType = "sqlite"
  const dbConnection = await createConnection({
    type: "sqlite",
    database: projectConfig.database_database,
    synchronize: true,
    entities,
fork icon0
star icon0
watch icon1

+ 135 other calls in file

18
19
20
21
22
23
24
25
26
27
    ...{ entities : [
        require('./entity/UserEntity')
    ]}
};
this.intitalazed = new Promise((resolve, reject) => {
    typeorm.createConnection(c).then((connection) => {
        this.connection = connection;
        resolve();
    })
    .catch(function(error) {
fork icon0
star icon0
watch icon1

131
132
133
134
135
136
137
138
139
140
 */
async function generateBizplce() {
  // 1. Create DB connection
  const opts = parseOptions()
  const ormconfig = await getOrmConfig(opts.mode)
  createConnection({
    ...ormconfig,
    logging: true
  }).then(async connection => {
    console.log(chalk.cyanBright.bold('Database connection established'))
fork icon0
star icon0
watch icon8

+ 15 other calls in file

63
64
65
66
67
68
69
70
71
72
TestService.prototype.getSeats = function () {
    return __awaiter(this, void 0, void 0, function () {
        var connection, test;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, typeorm_1.createConnection(__assign(__assign({}, connectionOptions_1.connectionOptions), { name: 'test' + Date.now() }))];
                case 1:
                    connection = _a.sent();
                    return [4 /*yield*/, connection.getRepository(seat_entity_1.SeatEntity).find()];
                case 2:
fork icon0
star icon0
watch icon0

127
128
129
130
131
132
133
134
135
136
return __generator(this, function (_a) {
    switch (_a.label) {
        case 0:
            looger = new common_1.Logger('Manufacturer');
            looger.debug('start');
            return [4 /*yield*/, typeorm_1.createConnection(__assign(__assign({}, connectionOptions_1.connectionOptions), { name: 'test5' + Date.now() }))];
        case 1:
            connection = _a.sent();
            return [4 /*yield*/, connection.getRepository(manufacturer_entity_1.ManufacturerEntity).find({ transaction: false })];
        case 2:
fork icon0
star icon0
watch icon0

+ 3 other calls in file