database

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, database Database)

Register globally registers a database.

Types

type Database

type Database interface {
	// Open returns a new database instance configured with parameters
	// coming from the URL string.
	Open(url string, subdir string) (Database, error)

	// Close closes the underlying  instance managed by the database.
	Close() error

	// Get reads the contents of a file or resource by name.
	// If there is no file available, it must return os.ErrNotExist.
	Get(file string) (contents string, err error)

	// Set writes the contents to a file or resource.
	Set(file string, contents string) error

	// Path get the full path of the database
	Path() (path string)
}

Database is the interface every database must implement.

How to implement?

  1. Implement this interface.
  2. Add a test that calls database/testing.go:Test()
  3. Add own tests for Open() and Close(). All other functions are tested by tests in database/testing. Saves you some time and makes sure all databases behave the same way.
  4. Call Register in init().

Guidelines:

  • All configuration input must come from the URL string in func Open()
  • Drivers are supposed to be read only.
  • Ideally don't load any contents (into memory) in Open

func Open

func Open(url string, subdir string) (Database, error)

Open returns a new database instance.

Directories

Path Synopsis
Package testing has the source tests.
Package testing has the source tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL