// openDBDriver is the callback provided during driver registration that opens
// an existing database for use.
543556
func openDBDriver(args ...interface{}) (database.DB, error) {
	dbPath, network, err := parseArgs("Open", args...)
	if err != nil {
		return nil, err
	}

	return openDB(dbPath, network, false)
}
890898
func (n *Node) OpenDatabase(name string, cache, handles int, namespace string) (ethdb.Database, error) {
	if n.config.DataDir == "" {
		return rawdb.NewMemoryDatabase(), nil
	}
	return rawdb.NewLevelDBDatabase(n.config.ResolvePath(name), cache, handles, namespace)
}
584078
func RegisterDriver(driver Driver) error {
	if _, exists := drivers[driver.DbType]; exists {
		str := fmt.Sprintf("driver %q is already registered",
			driver.DbType)
		return makeError(ErrDbTypeRegistered, str, nil)
	}

	drivers[driver.DbType] = &driver
	return nil
}
493344
func (r *RDBDriver) CloseDB() (err error) {
	if err = r.conn.Close(); err != nil {
		log.Errorf("Failed to close DB. Type: %s. err: %s", r.name, err)
		return
	}
	return
}
674574
func openDB(args *internal.ArgType) error {
	var err error

	// parse dsn
	u, err := dburl.Parse(args.DSN)
	if err != nil {
		return err
	}

	// save driver type
	args.LoaderType = u.Driver

	// grab loader
	var ok bool
	args.Loader, ok = internal.SchemaLoaders[u.Driver]
	if !ok {
		return errors.New("unsupported database type")
	}

	// open database connection
	args.DB, err = sql.Open(u.Driver, u.DSN)
	if err != nil {
		return err
	}

	return nil
}
126398
func NewDriver(hostName, storePath string) *Driver {
	return &Driver{
		BaseDriver: &drivers.BaseDriver{
			MachineName: hostName,
			StorePath:   storePath,
			SSHUser:     "docker",
		},
		CommonDriver:   &pkgdrivers.CommonDriver{},
		Boot2DockerURL: constants.DefaultISOURL,
		CPU:            constants.DefaultCPUS,
		DiskSize:       util.CalculateDiskSizeInMB(constants.DefaultDiskSize),
		Memory:         constants.DefaultMemory,
		PrivateNetwork: defaultPrivateNetworkName,
		Network:        defaultNetworkName,
		DiskPath:       filepath.Join(constants.GetMinipath(), "machines", config.GetMachineName(), fmt.Sprintf("%s.rawdisk", config.GetMachineName())),
		ISO:            filepath.Join(constants.GetMinipath(), "machines", config.GetMachineName(), "boot2docker.iso"),
	}
}
753615
func OpenDB(dbDriver string, dbInfo string) {
	db, err := gorm.Open(dbDriver, dbInfo)
	if err != nil {
		gormLog.Fatal("sql.Open failed", "error", err)
	}
	DB = db
	singulartable := revel.Config.BoolDefault("db.singulartable", false)
	if singulartable {
		DB.SingularTable(singulartable)
	}

}
1149235
func ShutdownDriver(rootDir string) error {
	driver, ok := driversByRoot[rootDir]
	if !ok {
		glog.Errorf("Tried to shut down uninitialized driver: %s", rootDir)
		return ErrDriverNotInit
	}
	glog.V(2).Infof("Shutting down %s driver for %s", driver.DriverType(), driver.Root())
	if err := driver.Cleanup(); err != nil {
		glog.Errorf("Unable to clean up %s driver for %s: %s", driver.DriverType(), driver.Root(), err)
		return err
	}
	delete(driversByRoot, rootDir)
	return nil
}
631510
func (dbGorp *DbGorp) OpenDb() (err error) {
	db, err := sql.Open(dbGorp.Info.DbDriver, dbGorp.Info.DbConnection)
	if err != nil {
		moduleLogger.Fatal("Open Database Error", "error", err)
	}

	// Create the database map
	dbGorp.Map = &gorp.DbMap{Db: db, Dialect: dbGorp.Info.Dialect}

	revel.OnAppStop(func() {
		revel.RevelLog.Info("Closing the database (from module)")
		if err := dbGorp.Close(); err != nil {
			revel.AppLog.Error("Failed to close the database", "error", err)
		}
	})

	return dbGorp.dbInit()
}
281012
func InitDriver(name DriverType, root string, args []string) error {
	// Make sure it is a driver that exists
	if init, exists := drivers[name]; exists {
		// Clean the path
		root = filepath.Clean(root)
		// If the driver already exists, return
		if _, exists := driversByRoot[root]; exists {
			return nil
		}
		// Can only add absolute paths
		if !path.IsAbs(root) {
			return ErrPathIsNotAbs
		}
		if name != DriverTypeNFS {
			// Check for an existing driver initialization that doesn't match
			if t, err := DetectDriverType(root); err != nil {
				if err != ErrDriverNotInit {
					return err
				}
			} else if t != name {
				glog.Errorf("Unable to initialize %s driver. Path %s has an existing %s volume driver.", name, root, t)
				return ErrDriverAlreadyInit
			}
		}
		// Create the directory
		if err := os.MkdirAll(root, 0755); err != nil && !os.IsExist(err) {
			return err
		}
		// Create the driver instance
		driver, err := init(root, args)
		if err != nil {
			return err
		}
		driversByRoot[root] = driver
		return nil
	}
	return ErrDriverNotSupported
}
738173
func NewDriver(a *Adaptor, filename string) *Driver {
	return &Driver{
		name:       gobot.DefaultName("Audio"),
		connection: a,
		interval:   500 * time.Millisecond,
		filename:   filename,
		halt:       make(chan bool, 0),
		Eventer:    gobot.NewEventer(),
		Commander:  gobot.NewCommander(),
	}
}
556527
func OpenDB(dbPath string) (*DB, error) {
	rand.Seed(time.Now().UnixNano()) // document ID generation relies on this RNG
	d, err := data.CreateOrReadConfig(dbPath)
	if err != nil {
		return nil, err
	}
	db := &DB{Config: d, path: dbPath, schemaLock: new(sync.RWMutex)}
	db.Config.CalculateConfigConstants()
	return db, db.load()
}
952262
func SupportedDrivers() []string {
	supportedDBs := make([]string, 0, len(drivers))
	for _, drv := range drivers {
		supportedDBs = append(supportedDBs, drv.DbType)
	}
	return supportedDBs
}
51801
func openDB(dbPath string, create bool) (walletdb.DB, error) {
	if !create && !fileExists(dbPath) {
		return nil, walletdb.ErrDbDoesNotExist
	}

	boltDB, err := bbolt.Open(dbPath, 0600, nil)
	return (*db)(boltDB), convertErr(err)
}
1247450
func NewIntegrationDriver(name string) (types.IntegrationDriver, error) {

	var ok bool
	var ctor types.NewIntegrationDriver

	func() {
		intDriverCtorsRWL.RLock()
		defer intDriverCtorsRWL.RUnlock()
		ctor, ok = intDriverCtors[strings.ToLower(name)]
	}()

	if !ok {
		return nil, goof.WithField("driver", name, "invalid driver name")
	}

	return NewIntegrationDriverManager(ctor()), nil
}
1067057
func openDb(dbData []byte) (*geoip2.Reader, error) {
	db, err := geoip2.FromBytes(dbData)
	if err != nil {
		return nil, fmt.Errorf("Unable to open database: %s", err)
	}
	return db, nil
}
984212
func Open(driverName, dataSourceName string) (*DB, error) {
	db, err := sql.Open(driverName, dataSourceName)
	if err != nil {
		return nil, err
	}
	return &DB{DB: db, driverName: driverName, Mapper: mapper()}, err
}