當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。