yolodb

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

yolodb is a simple in-memory database that supports basic CRUD operations.

Example
package main

import (
	"fmt"

	yoloDB "simonwaldherr.de/go/golibs/yoloDB"
)

func main() {
	// Erstellen einer neuen Datenbank
	db := yoloDB.NewDatabase()

	// Erstellen einer neuen Tabelle
	columns := []*yoloDB.Column{
		{Name: "id", Typ: "int"},
		{Name: "name", Typ: "string"},
		{Name: "age", Typ: "int"},
	}
	err := db.CreateTable("users", columns)
	if err != nil {
		panic(err)
	}

	// Einfügen von Datensätzen in die Tabelle
	data := map[string]interface{}{"id": 1, "name": "John Doe", "age": 30}
	err = db.Insert("users", data)
	if err != nil {
		panic(err)
	}
	data = map[string]interface{}{"id": 2, "name": "Jane Doe", "age": 32}
	err = db.Insert("users", data)
	if err != nil {
		panic(err)
	}

	// Auswählen von Datensätzen aus der Tabelle
	results, err := db.Select("users", []string{"name"}, []string{"age > 30"})
	if err != nil {
		panic(err)
	}
	fmt.Println("Results:")
	for _, record := range results {
		fmt.Println(record)
	}

}
Output:

Results:
map[name:Jane Doe]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name string
	Typ  string
}

Column is a struct that holds the column information.

type Database

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

Database is the main struct of the database.

func NewDatabase

func NewDatabase() *Database

NewDatabase returns a pointer to a new Database.

func (*Database) CreateTable

func (db *Database) CreateTable(name string, columns []*Column) error

CreateTable creates a new table in the database.

func (*Database) Delete

func (db *Database) Delete(name string, whereClauses []string) error

Delete deletes records from the table.

func (*Database) Insert

func (db *Database) Insert(name string, data map[string]interface{}) error

Insert inserts a new record into the table.

func (*Database) Select

func (db *Database) Select(name string, columns []string, whereClauses []string) ([]map[string]interface{}, error)

Select selects records from the table.

func (*Database) Update

func (db *Database) Update(name string, data map[string]interface{}, whereClauses []string) error

Update updates records in the table.

type Record

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

Record is a struct that holds the record information.

type Table

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

Table is a struct that holds the table information.

Jump to

Keyboard shortcuts

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