示例#1
0
文件: main.go 项目: willhite/noms-old
func getPersons(ds dataset.Dataset) types.Map {
	hv, ok := ds.MaybeHeadValue()
	if ok {
		return hv.(types.Map)
	} else {
		return types.NewMap()
	}
}
示例#2
0
文件: main.go 项目: willhite/noms-old
func addPerson(ds dataset.Dataset) {
	if flag.NArg() != 4 {
		fmt.Fprintln(os.Stderr, "Not enough arguments for command add-person")
		return
	}

	id, err := strconv.ParseUint(flag.Arg(1), 10, 64)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Invalid person-id: %s", flag.Arg(1))
		return
	}

	np := types.NewStruct("Person", map[string]types.Value{
		"id":    types.Number(id),
		"name":  types.String(flag.Arg(2)),
		"title": types.String(flag.Arg(3)),
	})

	ds.Commit(getPersons(ds).Set(types.Number(id), np))
}
示例#3
0
func writeTestData(ds dataset.Dataset, value types.Value) types.Ref {
	r1 := ds.Database().WriteValue(value)
	ds, err := ds.Commit(r1)
	d.Chk.NoError(err)
	err = ds.Database().Close()
	d.Chk.NoError(err)

	return r1
}
示例#4
0
func mergeDatasets(ds1, ds2 dataset.Dataset, v string) (dataset.Dataset, error) {
	return ds1.CommitWithParents(types.String(v), types.NewSet(ds1.HeadRef(), ds2.HeadRef()))
}
示例#5
0
func addBranchedDataset(newDs, parentDs dataset.Dataset, v string) (dataset.Dataset, error) {
	return newDs.CommitWithParents(types.String(v), types.NewSet().Insert(parentDs.HeadRef()))
}
示例#6
0
func addCommitWithValue(ds dataset.Dataset, v types.Value) (dataset.Dataset, error) {
	return ds.Commit(v)
}
示例#7
0
func addCommit(ds dataset.Dataset, v string) (dataset.Dataset, error) {
	return ds.Commit(types.String(v))
}
示例#8
0
func mergeDatasets(ds1, ds2 dataset.Dataset, v string) (dataset.Dataset, error) {
	p := types.NewSet(ds1.HeadRef(), ds2.HeadRef())
	return ds1.Commit(types.String(v), dataset.CommitOptions{Parents: p})
}
示例#9
0
func addBranchedDataset(newDs, parentDs dataset.Dataset, v string) (dataset.Dataset, error) {
	p := types.NewSet(parentDs.HeadRef())
	return newDs.Commit(types.String(v), dataset.CommitOptions{Parents: p})
}