Exemple #1
0
func (repo *TodoItemRepository) Insert(item *TodoItem) error {
	now := time.Now()
	item.CreatedAt = &now
	item.UpdatedAt = &now

	r, err := repo.DB.NamedExec(TODO_ITEM_INSERT_QUERY, item)
	if err != nil {
		return err
	}

	lastID, err := r.LastInsertId()
	if err != nil {
		return err
	}

	item.ID = dbtype.NewNullInt64(lastID)
	return nil
}
Exemple #2
0
func (repo *TodoListRepository) Insert(list *TodoList) error {
	now := time.Now()
	list.CreatedAt = &now
	list.UpdatedAt = &now

	r, err := repo.DB.NamedExec(TODO_LIST_INSERT_QUERY, list)
	if err != nil {
		return err
	}

	lastID, err := r.LastInsertId()
	if err != nil {
		return err
	}

	list.ID = dbtype.NewNullInt64(lastID)
	return nil
}
Exemple #3
0
func (repo *TodoGroupRepository) Insert(group *TodoGroup) error {
	now := time.Now()
	group.CreatedAt = &now
	group.UpdatedAt = &now

	r, err := repo.DB.NamedExec(TODO_GROUP_INSERT_QUERY, group)
	if err != nil {
		return err
	}

	lastID, err := r.LastInsertId()
	if err != nil {
		return err
	}

	group.ID = dbtype.NewNullInt64(lastID)
	return nil
}