// MustOpen opens a database and establishes a connection to it.
// Please refer to sql.Open() and sql.Ping() for more information.
499495
func MustOpen(driverName, dsn string) (*DB, error) {
	db, err := Open(driverName, dsn)
	if err != nil {
		return nil, err
	}
	if err := db.sqlDB.Ping(); err != nil {
		return nil, err
	}
	return db, nil
}
1076741
func (db *DB) MustExecute(stmt Executable, args ...interface{}) sql.Result {
	s, params, err := db.compile(stmt)
	if err != nil {
		log.Panicf(
			"aspect: failed to compile (%s): %s",
			stmt,
			err,
		)
	}
	if len(args) == 0 {
		args = params.args
	}
	result, err := db.conn.Exec(s, args...)
	if err != nil {
		log.Panicf(
			"aspect: failed to exec (%s) with parameters (%v): %s",
			s,
			args,
			err,
		)
	}
	return result
}
742561
func openDB(driver, config string) *sql.DB {
	db, err := sql.Open(driver, config)
	if err != nil {
		log.Fatalln("database connection failed:", err)
	}
	if driver == "mysql" {
		// per issue https://github.com/go-sql-driver/mysql/issues/257
		db.SetMaxIdleConns(0)
	}
	if err := pingDatabase(db); err != nil {
		log.Fatalln("database ping attempts failed:", err)
	}
	return db
}
989616
func (tpc *TwoPC) Open(dbconfigs *dbconfigs.DBConfigs) {
	tpc.readPool.Open(dbconfigs.AppWithDB(), dbconfigs.DbaWithDB(), dbconfigs.DbaWithDB())
}
243140
func (e *CheckTableExec) Open(ctx context.Context) error {
	if err := e.baseExecutor.Open(ctx); err != nil {
		return err
	}
	e.done = false
	return nil
}
45896
func (d *Datasource) Connect() (*sql.DB, error) {
	return sql.Open(d.Driver, d.DSN)
}
1099172
func (q *BooleanQuery) Must(query FtsQuery) *BooleanQuery {
	switch val := query.(type) {
	case ConjunctionQuery:
		q.data.Must = &val
	case *ConjunctionQuery:
		q.data.Must = val
	default:
		q.data.Must = NewConjunctionQuery(val)
	}
	return q
}
1123372
func OpenDB(databaser Databaser, dirpath string) (*Database, error) {
	err := databaser.Open(dirpath)
	if err != nil {
		simlog.Errorf("failed to open database. err = %s", err)
		return nil, err
	}
	return &Database{databaser}, nil
}
951078
func (e *CheckIndexExec) Open(ctx context.Context) error {
	if err := e.baseExecutor.Open(ctx); err != nil {
		return err
	}
	if err := e.src.Open(ctx); err != nil {
		return err
	}
	e.done = false
	return nil
}
1127796
func (r *RedisDriver) OpenDB(dbType, dbPath string, debugSQL bool) (err error) {
	var option *redis.Options
	if option, err = redis.ParseURL(dbPath); err != nil {
		log.Errorf("%s", err)
		return fmt.Errorf("Failed to Parse Redis URL. dbpath: %s, err: %s", dbPath, err)
	}
	r.conn = redis.NewClient(option)
	if err = r.conn.Ping().Err(); err != nil {
		return fmt.Errorf("Failed to open DB. dbtype: %s, dbpath: %s, err: %s", dbType, dbPath, err)
	}
	return nil
}
236236
func MustLoad(filenames ...string) {
	err := Load(filenames...)
	if err != nil {
		panic(err.Error())
	}
}
1244589
func (o *openHelper) Open(ctx context.Context, op opener) {
	if o.err != nil {
		return
	}
	o.err = op.Open(ctx)
	if o.err == nil {
		o.opened = append(o.opened, op)
	}
}
1204705
func Open(table []byte, paths ...string) error {
	if inst == nil {
		return errors.New("forgot to import the driver")
	}
	db = inst(paths...)
	return db.Register(table)
}
1374412
func (s *SNMP) Open() (err error) {
	if s.conn != nil {
		return
	}

	err = retry(int(s.args.Retries), func() error {
		conn, e := net.DialTimeout(s.args.Network, s.args.Address, s.args.Timeout)
		if e == nil {
			s.conn = conn
		}
		return e
	})
	if err != nil {
		return
	}

	s.engine = newSNMPEngine(s.args)
	if err = s.engine.Discover(s); err != nil {
		s.Close()
	}
	return
}
1251490
func (e *ShowDDLJobQueriesExec) Open(ctx context.Context) error {
	if err := e.baseExecutor.Open(ctx); err != nil {
		return err
	}
	txn, err := e.ctx.Txn(true)
	if err != nil {
		return err
	}
	jobs, err := admin.GetDDLJobs(txn)
	if err != nil {
		return err
	}
	historyJobs, err := admin.GetHistoryDDLJobs(txn, admin.DefNumHistoryJobs)
	if err != nil {
		return err
	}

	e.jobs = append(e.jobs, jobs...)
	e.jobs = append(e.jobs, historyJobs...)

	return nil
}
977002
func (adapter *PostgresAdapter) Open(dbURL string) (*sql.DB, error) {
	db, err := sql.Open("postgres", dbURL)
	if err != nil {
		adapter.Log.Info("msg", "Error creating database connection", "err", err)
		return nil, err
	}

	// if there is a supplied Schema
	if adapter.Schema != "" {
		if err = db.Ping(); err != nil {
			adapter.Log.Info("msg", "Error opening database connection", "err", err)
			return nil, err
		}

		var found bool

		query := Cleanf(`SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace n WHERE n.nspname = '%s');`, adapter.Schema)
		adapter.Log.Info("msg", "FIND SCHEMA", "query", query)

		if err := db.QueryRow(query).Scan(&found); err == nil {
			if !found {
				adapter.Log.Warn("msg", "Schema not found")
			}
			adapter.Log.Info("msg", "Creating schema")

			query = Cleanf("CREATE SCHEMA %s;", adapter.Schema)
			adapter.Log.Info("msg", "CREATE SCHEMA", "query", query)

			if _, err = db.Exec(query); err != nil {
				if adapter.ErrorEquals(err, types.SQLErrorTypeDuplicatedSchema) {
					adapter.Log.Warn("msg", "Duplicated schema")
					return db, nil
				}
			}
		} else {
			adapter.Log.Info("msg", "Error searching schema", "err", err)
			return nil, err
		}
	} else {
		return nil, fmt.Errorf("no schema supplied")
	}

	return db, err
}
491417
func Open(driver, config string) shimmie.Store {
	db := openDB(driver, config)
	return &datastore{db}
}