database

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 3 Imported by: 0

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