Skip to content

Simple Go library for in-memory data storage with file persistence.

License

Notifications You must be signed in to change notification settings

karlmcguire/dump

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dump

GoDoc Go Report Card Coverage

Simple Go library for in-memory data storage with file persistence.

features

  • No data races
  • Everything is stored in memory
  • Multiple ways to persist to disk
  • Small and fast

what is this for?

I wanted a safe way to access Go slices from multiple goroutines and the ability to save those slices to the disk. This is useful for APIs (see example) that require fast data access.

persistence

Dumps save to the disk (usually with a ".db" file extension). There are currently three persistence settings available.

manually

Using the dump.PERSIST_MANUAL constant allows you to control when the dump is saved to disk. You can manually save the dump by calling the *Dump.Save() function.

... = dump.NewDump(..., dump.PERSIST_MANUAL, ...)

on writes

Using the dump.PERSIST_WRITES constant will cause the dump to save to disk when *Dump.Add() or *Dump.Update() is called.

... = dump.NewDump(..., dump.PERSIST_WRITES, ...)

on an interval

Using the dump.PERSIST_INTERVAL constant will cause the dump to save to disk on a timed interval (currently 60 seconds).

... = dump.NewDump(..., dump.PERSIST_INTERVAL, ...)

examples

creating a dump

users, err := dump.NewDump("users.db", dump.PERSIST_WRITES, dump.Type{"main.User", User{}})

adding an item

// id is assigned to the index location of the item after it is added
id, err := users.Add(&User{Name: "karl"})

getting an item

err := users.View(func(items []dump.Item) error {
    println(items[id].(*User).Name) // will output "karl"
    return nil
})

updating an item

err := users.Update(func(items []dump.Item) error {
    items[id].(*User).Name = "santa"
    return nil
})

About

Simple Go library for in-memory data storage with file persistence.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages