func init() {
	var err error
	db, err = gmq.Open("mysql", "root@/blog")
	if err != nil {
		panic(err)
	}
	gmq.Debug = true
}
func init() {
	var err error
	pqdb, err = gmq.Open("postgres", "dbname=blog sslmode=disable")
	if err != nil {
		panic(err)
	}
	gmq.Debug = true
	log.SetFlags(log.LstdFlags | log.Lshortfile)
}
Exemple #3
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
}
Exemple #4
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
}