db

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/eng618/go-eng/interview/db"
)

func main() {
	db := db.NewDatabase()

	t := db.Set("foo", "bar")
	fmt.Println("just set foo to:", db.Get("foo"))

	db.Set("foo", "baz")
	fmt.Println("the latest foo is:", db.Get("foo"))

	// You can use the common ok idiom to get a key with a particular time stamp.
	if val, ok := db.GetForTime("foo", t); ok {
		fmt.Println("the foo at", t, ":", val)
	}

	db.Set("age", 36)
	age := db.Get("age")
	fmt.Println("the age in database is:", age)

	db.Print()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InMemDB

type InMemDB struct {
	// contains filtered or unexported fields
}

InMemDB is a simple in memory database.

func NewDatabase

func NewDatabase() *InMemDB

NewDatabase instantiates a new instance of a database.

func (*InMemDB) Get

func (db *InMemDB) Get(key string) interface{}

Get attempts to retrieve the supplied key from an existing database.

func (*InMemDB) GetForTime

func (db *InMemDB) GetForTime(key string, t time.Time) (interface{}, bool)

Get attempts to retrieve the supplied key from an existing database.

func (*InMemDB) Print

func (db *InMemDB) Print()

Print is a helper method to print each entry in a database to it's own line.

func (*InMemDB) Set

func (db *InMemDB) Set(key string, value interface{}) time.Time

Set creates a new entry into an existing database.

Jump to

Keyboard shortcuts

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