microo8 / mimir Goto Github PK
View Code? Open in Web Editor NEWGenerates minimal embedded database from structs in golang; moved to gitlab.com/microo8/mimir
Generates minimal embedded database from structs in golang; moved to gitlab.com/microo8/mimir
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
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:
func inc(b []byte) {
for j := 0; j < len(b); j++ {
b[j]++
if b[j] > 0 {
break
}
}
}
persons.AddWithId([]byte{0,0,0,1}, person)
I would expect you to address this issue, because I greatly enjoyed mimir use in my new project.
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)
This is how to write multiple in tag.
http://stackoverflow.com/questions/18635671/how-to-define-multiple-name-tags-in-a-struct
For example:
what about considering support struct like this:
type HeartBeat struct {
Ip string `index:"ip" json:"ip"`
Version string `index:"version" json:"version"`
CreatedAt time.Time `index:"created_at" json:"created_at"`
Status string `json:"status"`
// DeletedAt time.Time `index:"deleted_at"`
}
could you put a .sh script in to show how to run the generation ?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.