Beispiel #1
0
// Projects
func (self *Database) Create(colName string, item interface{}) error {
	/*s := structs.New(item)
	colName := ""
	for _, f := range s.Fields() {
		colName = f.Tag("col")
		if colName != "" {
			break
		}

	}

	if colName == "" {
		return errors.New("col name")
	}*/

	col := self.db.Use(colName)
	m := structs.Map(item)
	i, e := col.Insert(m)
	if e == nil {
		for _, field := range structs.Fields(item) {
			if field.Name() == "Id" || field.Name() == "ID" {
				field.Set(fmt.Sprintf("%d", i))
			}
		}
	}
	return e
}
Beispiel #2
0
func getColName(item interface{}) string {
	var colName string
	for _, f := range structs.Fields(item) {
		colName = f.Tag("col")
		if colName != "" {
			break
		}
	}
	return colName
}