Example #1
0
export default () =>
  createConnection({
    type: "sqlite",
    database: dbPath,
    entities: [__dirname + "/../models/*.js"],
    synchronize: true,
  }).then(conn => {
    connection = conn;
  });
Example #2
0
export function connect(driver: DriverOptions): Promise<Connection> {
  return createConnection({
    driver: Object.assign(driver),
    entities: [
      Phone,
    ],
    autoSchemaSync: false,
  });
}
Example #3
0
function main() {
  createConnection(getPostgresConfig())
    .then(() => {
      console.log('database connection successful.');

      startServer();
      startToolServer();
    })
    .catch(error => console.log(error));
}
 useFactory: async (configService: ConfigService) =>
   await createConnection({
     type: "postgres",
     host: configService.getString("DB_HOST"),
     port: configService.getNumber("DB_PORT"),
     username: configService.getString("DB_USER"),
     password: configService.getString("DB_PWD"),
     database: configService.getString("DB_NAME"),
     entities: [__dirname + "/../../**/*.entity{.ts,.js}"],
     synchronize: true
   }),
 useFactory: async () => await createConnection({
     type: 'mssql',
     host: 'localhost',
     port: 1433,
     username: '******',
     password: '******',
     database: 'IronManNest',
     entities: [
         __dirname + '/Users/*.entity{.ts,.js}'
     ]
 })
 useFactory: async () => await createConnection({
   type: 'mysql',
   host: 'localhost',
   port: 3306,
   username: '******',
   password: '******',
   database: 'test',
   entities: [
     __dirname + '/../**/**.entity.ts',
   ],
   autoSchemaSync: true,
 }),
Example #7
0
 return async () => {
     if(connection == null) {
         connection = await createConnection({
             type: 'sqlite',
             database: 'my.db',
             entities: [
                 Todo
             ],
             synchronize: true
         });
     }
     return connection;
 }
Example #8
0
const newConnection = async () => {
  const con = await createConnection({
    host: 'localhost',
    type: 'mysql',
    username: '******',
    password: '******',
    database: 'typeorm_test',
    entities,
    synchronize: true,
    logging: ['error', 'query'],
  })

  return con
}
Example #9
0
(async () => {
    try{
        let connection = await createConnection(dbOptions);

        console.log("connection.isConnected = " + connection.isConnected);

        await connection.getRepository(FooEntity).find(); // this will throw ECONNREFUSED

        console.log("Mysql connection ok");
    }
    catch(e){
        console.error("Mysql connection error : " + e );
    }
})();
    private createConnections() {
        let promises: Promise<any>[] = [];

        if (this.configuration.connection)
            promises.push(createConnection(this.normalizeConnectionOptions(this.configuration.connection)));

        if (this.configuration.connections)
                this.configuration
                    .connections
                    .map(connectionOptions => createConnection(this.normalizeConnectionOptions(connectionOptions)))
                    .forEach(closePromise => promises.push(closePromise));

        return Promise.all(promises);
    }