GithubHelp home page GithubHelp logo

microo8 / mimir Goto Github PK

View Code? Open in Web Editor NEW
39.0 5.0 6.0 183 KB

Generates minimal embedded database from structs in golang; moved to gitlab.com/microo8/mimir

embedded-database golang code-generation

mimir's Introduction

Project moved to gitlab.com/microo8/mimir

mimir's People

Contributors

h4ck3rm1k3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mimir's Issues

Qt

I like this codgen approach.

I need to get this working with therecipe/Qt code, which I noticed your also using. So that would be a good test case.

So am happy to work on this with you if you want

rand.Int() not the best way for the id.

  1. Collisions should not be allowed.
  2. ID range may be very large(In my current project I'm not sure that's enough uint64).

I propose to use []byte as an identifier.
You can allow the user to select the number of bytes for the index.
And a choice of two options:

  1. autoincrement (without affecting the user part of mimir)
    something like that:
func inc(b []byte) {
    for j := 0; j < len(b); j++ {
        b[j]++
        if b[j] > 0 {
            break
        }
    }
}
  1. User-defined identifier in operations
    something like that:
    persons.AddWithId([]byte{0,0,0,1}, person)
    Anyway, rand.Int() not the best way for the identifier field in production.

I would expect you to address this issue, because I greatly enjoyed mimir use in my new project.

Structure with field type []byte is not working.

Simple struct

type ByteStruct struct {
    ByteTest []byte `index:"ByteTest"`
}

does not work with mimir.

Generate error: format source error: $374:21: expected operand, found ']' (and 10 more errors)

test2

could you put a .sh script in to show how to run the generation ?

Update function in template does not work correctly

Following code results in the following error (the first iteration of the last loop):
"unexpected end of JSON input"

This error does not occur without "persons.Update".

$GOPATH/mypackage/db/structs.go:

package db

type Person struct {
    Name string
    Age            int `index:"Age"`
}

$GOPATH/mypackage/main.go:

package main

import (
    "os"
    "mypackage/db"
    "fmt"
    "encoding/json"
)

func main() {
    os.RemoveAll("testdb")
    db2, err := db.OpenDB("dbb", json.Marshal, json.Unmarshal)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    persons := db2.Persons()
    id, err := persons.Add(&db.Person{
        Name: "Foo",
        Age: 20,
    })

    if err != nil {
        panic(err)
    }

    person, err := persons.Get(id)
    if err != nil {
        panic(err)
    }
    fmt.Println(person.Name, person.Age)

    person.Name = "Meh"
    err = persons.Update(id, person)
    if err != nil {
        panic(err)
    }

    iter := persons.All()
    for iter.Next() {
        p,err := iter.Value()
        if err!=nil {
            fmt.Println(err)
            os.Exit(1)
        }
        fmt.Println(p.Name, p.Age)
    }
}

Functions "Add" and "Update" in the template must be the same, except for a few lines
But I can see the difference:
Add:

err = col.db.{{$structName}}s().addIndex([]byte("${{$structName}}"), batch, id, obj)

Update:

err = col.addIndex([]byte("{{$structName}}"), batch, id, obj)

Also in the template is not a function "Delete", which is in the examples.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.