当前位置: 首页>>代码示例>>Golang>>正文


Golang TableDescriptor.AllocateIDs方法代码示例

本文整理汇总了Golang中github.com/cockroachdb/cockroach/sql.TableDescriptor.AllocateIDs方法的典型用法代码示例。如果您正苦于以下问题:Golang TableDescriptor.AllocateIDs方法的具体用法?Golang TableDescriptor.AllocateIDs怎么用?Golang TableDescriptor.AllocateIDs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cockroachdb/cockroach/sql.TableDescriptor的用法示例。


在下文中一共展示了TableDescriptor.AllocateIDs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestAllocateIDs

func TestAllocateIDs(t *testing.T) {
	defer leaktest.AfterTest(t)

	desc := sql.TableDescriptor{
		ID:       keys.MaxReservedDescID + 2,
		ParentID: keys.MaxReservedDescID + 1,
		Name:     "foo",
		Columns: []sql.ColumnDescriptor{
			{Name: "a"},
			{Name: "b"},
			{Name: "c"},
		},
		PrimaryIndex: sql.IndexDescriptor{Name: "c", ColumnNames: []string{"a", "b"}},
		Indexes: []sql.IndexDescriptor{
			{Name: "d", ColumnNames: []string{"b", "a"}},
			{Name: "e", ColumnNames: []string{"b"}},
		},
		Privileges: sql.NewDefaultPrivilegeDescriptor(),
	}
	if err := desc.AllocateIDs(); err != nil {
		t.Fatal(err)
	}

	expected := sql.TableDescriptor{
		ID:       keys.MaxReservedDescID + 2,
		ParentID: keys.MaxReservedDescID + 1,
		Version:  1,
		Name:     "foo",
		Columns: []sql.ColumnDescriptor{
			{ID: 1, Name: "a"},
			{ID: 2, Name: "b"},
			{ID: 3, Name: "c"},
		},
		PrimaryIndex: sql.IndexDescriptor{
			ID: 1, Name: "c", ColumnIDs: []sql.ColumnID{1, 2}, ColumnNames: []string{"a", "b"}},
		Indexes: []sql.IndexDescriptor{
			{ID: 2, Name: "d", ColumnIDs: []sql.ColumnID{2, 1}, ColumnNames: []string{"b", "a"}},
			{ID: 3, Name: "e", ColumnIDs: []sql.ColumnID{2}, ColumnNames: []string{"b"},
				ImplicitColumnIDs: []sql.ColumnID{1}},
		},
		Privileges:   sql.NewDefaultPrivilegeDescriptor(),
		NextColumnID: 4,
		NextIndexID:  4,
	}
	if !reflect.DeepEqual(expected, desc) {
		a, _ := json.MarshalIndent(expected, "", "  ")
		b, _ := json.MarshalIndent(desc, "", "  ")
		t.Fatalf("expected %s, but found %s", a, b)
	}

	if err := desc.AllocateIDs(); err != nil {
		t.Fatal(err)
	}
	if !reflect.DeepEqual(expected, desc) {
		a, _ := json.MarshalIndent(expected, "", "  ")
		b, _ := json.MarshalIndent(desc, "", "  ")
		t.Fatalf("expected %s, but found %s", a, b)
	}
}
开发者ID:mbertschler,项目名称:cockroach,代码行数:59,代码来源:structured_test.go

示例2: TestAllocateIDs

func TestAllocateIDs(t *testing.T) {
	defer leaktest.AfterTest(t)

	desc := sql.TableDescriptor{
		ID:   sql.MaxReservedDescID + 1,
		Name: "foo",
		Columns: []sql.ColumnDescriptor{
			{Name: "a"},
			{Name: "b"},
		},
		PrimaryIndex: sql.IndexDescriptor{Name: "c", ColumnNames: []string{"a"}},
		Indexes: []sql.IndexDescriptor{
			{Name: "d", ColumnNames: []string{"b", "a"}},
		},
		Privileges: sql.NewDefaultDatabasePrivilegeDescriptor(),
	}
	if err := desc.AllocateIDs(); err != nil {
		t.Fatal(err)
	}

	expected := sql.TableDescriptor{
		ID:   sql.MaxReservedDescID + 1,
		Name: "foo",
		Columns: []sql.ColumnDescriptor{
			{ID: 1, Name: "a"},
			{ID: 2, Name: "b"},
		},
		PrimaryIndex: sql.IndexDescriptor{ID: 1, Name: "c", ColumnIDs: []sql.ColumnID{1}, ColumnNames: []string{"a"}},
		Indexes: []sql.IndexDescriptor{
			{ID: 2, Name: "d", ColumnIDs: []sql.ColumnID{2, 1}, ColumnNames: []string{"b", "a"}},
		},
		Privileges:   sql.NewDefaultDatabasePrivilegeDescriptor(),
		NextColumnID: 3,
		NextIndexID:  3,
	}
	if !reflect.DeepEqual(expected, desc) {
		t.Fatalf("expected %+v, but found %+v", expected, desc)
	}
}
开发者ID:wuguojun,项目名称:cockroach,代码行数:39,代码来源:structured_test.go


注:本文中的github.com/cockroachdb/cockroach/sql.TableDescriptor.AllocateIDs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。