Ejemplo n.º 1
0
func (m MysqlDriver) LoadDatabaseSchema(dsnString, schema, tableNames string) (DbSchema, error) {
	log.Printf("[MySQL Driver] Start to load tables schema from db, %s, tables=%s", schema, tableNames)
	db, err := gmq.Open("mysql", m.useInformationSchema(dsnString, schema))
	if err != nil {
		return nil, err
	}
	defer db.Close()

	if err = db.Ping(); err != nil {
		return nil, err
	}

	dbSchema := make(DbSchema)
	if err = m.queryColumns(db, schema, tableNames, dbSchema); err != nil {
		return nil, err
	}
	log.Printf("[MySQL Driver] Loaded schema data of %d tables from db[%s]", len(dbSchema), schema)
	return dbSchema, nil
}
Ejemplo n.º 2
0
func (p PostgresDriver) LoadDatabaseSchema(dsnString, schema, tableNames string) (DbSchema, error) {
	log.Printf("[Postgres Driver] Start to load tables schema from database, %s, tables=%s", schema, tableNames)
	db, err := gmq.Open("postgres", dsnString)
	if err != nil {
		return nil, err
	}
	defer db.Close()

	if err = db.Ping(); err != nil {
		return nil, err
	}

	dbSchema := make(DbSchema)
	if err = p.queryColumns(db, schema, tableNames, dbSchema); err != nil {
		return nil, err
	}
	log.Printf("[Postgres Driver] Loaded schema data of %d tables from database schema[%s]", len(dbSchema), schema)
	return dbSchema, nil
}