typeorm#createConnections TypeScript Examples

The following examples show how to use typeorm#createConnections. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MysqlHelper.ts    From Designer-Server with GNU General Public License v3.0 6 votes vote down vote up
static showTables = async(connectOption: ConnectionOptions) => {
    return new Promise(async(resolve, reject) => {
      const name = connectOption.name;
      let tables = []
      try {
        await createConnections([connectOption])
        const manager = await getManager(name)
        const results = await manager.query("SHOW tables;");
        
        
        results.forEach(row => {
          tables.push(row[`Tables_in_${connectOption.database}`]);
        });
      } catch(err) {
        await getConnection(name).close();
        reject(err);
        return;
      } finally {
        await getConnection(name).close();
      }
      resolve(tables);
    });
  };
Example #2
Source File: MysqlHelper.ts    From Designer-Server with GNU General Public License v3.0 6 votes vote down vote up
static showTableStatus = async(connectOption: ConnectionOptions):Promise<MysqlTableStatus[]> => {
    return new Promise(async(resolve, reject) => {
      const name = connectOption.name;
      let tableStatuses:MysqlTableStatus[] = []
      try {
        await createConnections([connectOption])
        const manager = await getManager(name)
        tableStatuses = await manager.query("SHOW TABLE STATUS;");
      } catch(err) {
        await getConnection(name).close();
        reject(err);
        return;
      } finally {
        await getConnection(name).close();
      }
      resolve(tableStatuses);
    });
  };
Example #3
Source File: MysqlHelper.ts    From Designer-Server with GNU General Public License v3.0 6 votes vote down vote up
static getColumns = async(connectOption: ConnectionOptions, table: string):Promise<MetaColumn[]> => {
    return new Promise(async(resolve, reject) => {
      const name = connectOption.name;
      let mysqlDescribeResults:MysqlDescribeResult[] = []
      let columns: MetaColumn[] = []
      try {
        await createConnections([connectOption])
        const manager = await getManager(name)
        mysqlDescribeResults = await manager.query(`DESCRIBE \`${table}\`;`);
        mysqlDescribeResults.forEach( result => {
          const metaCol = new MetaColumn();
          metaCol.originalColumnName = result.Field;
          metaCol.columnName = result.Field;
          const convertedType = MysqlHelper.convertType(result.Type);
          metaCol.type = convertedType.type;
          if(convertedType.size) metaCol.size = convertedType.size;
          columns.push(metaCol);
        })
      } catch(err) {
        await getConnection(name).close();
        reject(err);
        return;
      } finally {
        await getConnection(name).close();
      }
      resolve(columns);
    })
  }
Example #4
Source File: application-lifecycle.ts    From malagu with MIT License 6 votes vote down vote up
async onStart(app: Application): Promise<void> {
        const connections = getConnectionManager().connections;
        for (const c of connections) {
            if (c.isConnected) {
                await c.close();
            }
        }
        const { ormConfig } = this.options;
        let configs: any[];
        if (Array.isArray(ormConfig)) {
            configs = ormConfig;
        } else {
            ormConfig.name = DEFAULT_CONNECTION_NAME;
            configs = [ ormConfig ];
        }

        for (const config of configs) {
            config.entities = EntityProvider.getEntities(config.name) || [];
        }

        await createConnections(configs);
    }
Example #5
Source File: index.ts    From gobarber-api with MIT License 5 votes vote down vote up
createConnections();