fuck this reflection shit, i'm using codegen....
This commit is contained in:
parent
93b81308cb
commit
f92f447f73
13
document.go
13
document.go
@ -7,12 +7,13 @@ import (
|
|||||||
|
|
||||||
type Document struct {
|
type Document struct {
|
||||||
// Created time. updated/added automatically.
|
// Created time. updated/added automatically.
|
||||||
Created time.Time `bson:"createdAt" json:"createdAt"`
|
Created time.Time `bson:"createdAt" json:"createdAt" tstype:"Date"`
|
||||||
// Modified time. updated/added automatically.
|
// Modified time. updated/added automatically.
|
||||||
Modified time.Time `bson:"updatedAt" json:"updatedAt"`
|
Modified time.Time `bson:"updatedAt" json:"updatedAt" tstype:"Date"`
|
||||||
model *Model `bson:"-"`
|
model *Model `bson:"-"`
|
||||||
exists bool `bson:"-"`
|
exists bool `bson:"-"`
|
||||||
self any `bson:"-"`
|
self any `bson:"-"`
|
||||||
|
populatedFields map[string]bool `bson:"-"`
|
||||||
}
|
}
|
||||||
type IDocument interface {
|
type IDocument interface {
|
||||||
Append(field string, a ...interface{}) error
|
Append(field string, a ...interface{}) error
|
||||||
@ -32,6 +33,8 @@ type IDocument interface {
|
|||||||
serializeToStore() any
|
serializeToStore() any
|
||||||
getModel() *Model
|
getModel() *Model
|
||||||
setModel(m Model)
|
setModel(m Model)
|
||||||
|
markPopulated(field string)
|
||||||
|
markDepopulated(field string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type SaveOptions struct {
|
type SaveOptions struct {
|
||||||
|
@ -266,3 +266,11 @@ func incrementAll(item interface{}) {
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Document) markPopulated(field string) {
|
||||||
|
d.populatedFields[field] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Document) markDepopulated(field string) {
|
||||||
|
d.populatedFields[field] = false
|
||||||
|
}
|
||||||
|
5
model.go
5
model.go
@ -193,6 +193,11 @@ func (m *Model) FindOne(query interface{}, options *options.FindOneOptionsBuilde
|
|||||||
return qq, err
|
return qq, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Model) Count(query interface{}, options *options.CountOptionsBuilder) (int64, error) {
|
||||||
|
coll := m.getColl()
|
||||||
|
return coll.CountDocuments(context.TODO(), query, options)
|
||||||
|
}
|
||||||
|
|
||||||
func createBase(d any) (reflect.Value, int, string) {
|
func createBase(d any) (reflect.Value, int, string) {
|
||||||
var n string
|
var n string
|
||||||
var ri *Model
|
var ri *Model
|
||||||
|
4
query.go
4
query.go
@ -28,6 +28,8 @@ const (
|
|||||||
OP_FIND = "find"
|
OP_FIND = "find"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var nilVal = reflect.Zero(reflect.TypeFor[any]())
|
||||||
|
|
||||||
func populate(r Reference, rcoll string, rawDoc interface{}, d string, src interface{}) any {
|
func populate(r Reference, rcoll string, rawDoc interface{}, d string, src interface{}) any {
|
||||||
rt := reflect.TypeOf(src)
|
rt := reflect.TypeOf(src)
|
||||||
rv := reflect.ValueOf(src)
|
rv := reflect.ValueOf(src)
|
||||||
@ -399,7 +401,7 @@ func rerere(input interface{}, resType reflect.Type) interface{} {
|
|||||||
fv.Set(reflect.ValueOf(tmp))
|
fv.Set(reflect.ValueOf(tmp))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fv.Set(reflect.Zero(ft.Type))
|
fv.Set(reflect.ValueOf(nil))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user