Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

MorganPeterson/mdb-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NOTICE

Source code has been moved to Sourcehut and this repository has been archived.

MDB

MDB is a simple JSON file database written in Go.

MDB is meant to be used for toy projects as a simple alternative to loading in large database systems. It is a hobby project at best.

Usage

import (
    "fmt"

    "github.com/MorganPeterson/mdb"
)

func main() {
	db := NewDatabase()
	
	err := Load(db, "db.json")
	if err != nil {
		fmt.Println(err.Error())
	}

	id, err := Put(db, "hello 1")
	if err != nil {
		fmt.Println(err.Error())
	}

	err = Update(db, id, "hello 1 updated")
	if err != nil {
		fmt.Println(err.Error())
	}

	dId, err := Put(db, "hello 2")
	if err != nil {
		fmt.Println(err.Error())
	}

	err = Delete(db, dId)
	if err != nil {
		fmt.Println(err.Error())
	}

	err = Commit(db, "db.json")
}

Resulting JSON file:

{
  "data": {
    "2144D9F4-B57B-44E3-90CB-4F26BB696E77": {
      "created": "2023-11-24 16:11:05.880023432 +0000 UTC",
      "edited": "2023-11-24 16:11:05.880027792 +0000 UTC",
      "doc": "hello 1 updated"
    }
  }
}

About

A Golang JSON file database package.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages