Skip to content

Commit

Permalink
Remove Collection from Document (#318)
Browse files Browse the repository at this point in the history
We can use Project to separate documents and manage them.

For now, this commit removes Collection and it will be implemented when
the index or search function is strengthened in the future.
  • Loading branch information
hackerwins authored May 2, 2022
1 parent d57f04c commit 149693a
Show file tree
Hide file tree
Showing 45 changed files with 543 additions and 925 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Yorkie consists of three main components: Client, Document and Agent.
```
Client "A" (Go) Server MemDB or MongoDB
┌───────────────────┐ ┌────────────────────────┐ ┌───────────┐
│ Document "D-1" │◄─Changes─►│ Collection "C-1" │ │ Changes │
│ Document "D-1" │◄─Changes─►│ Project "P-1" │ │ Changes │
│ { a: 1, b: {} } │ │ ┌───────────────────┐ │◄─►│ Snapshots │
└───────────────────┘ │ │ Document "D-1" │ │ └───────────┘
Client "B" (JS) │ │ { a: 2, b: {} } │ │
Expand All @@ -30,7 +30,7 @@ Yorkie consists of three main components: Client, Document and Agent.
Admin (CLI, Web) │ │
┌────────────────────┐ └────────────────────────┘
│ Query "Q-1" │ ▲
db[c-1].find({a:2})├───DB Query───┘
P-1.find({a:2}) ├───DB Query───┘
└────────────────────┘
```

Expand Down
8 changes: 4 additions & 4 deletions api/converter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestConverter(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "{}", obj.Marshal())

doc := document.New("c1", "d1")
doc := document.New("d1")

err = doc.Update(func(root *proxy.ObjectProxy) error {
root.SetNewText("k1").Edit(0, 0, "A")
Expand All @@ -62,7 +62,7 @@ func TestConverter(t *testing.T) {
})

t.Run("snapshot test", func(t *testing.T) {
doc := document.New("c1", "d1")
doc := document.New("d1")

err := doc.Update(func(root *proxy.ObjectProxy) error {
// an object and primitive types
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestConverter(t *testing.T) {
})

t.Run("change pack test", func(t *testing.T) {
d1 := document.New("c1", "d1")
d1 := document.New("d1")

err := d1.Update(func(root *proxy.ObjectProxy) error {
// an object and primitive types
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestConverter(t *testing.T) {
assert.NoError(t, err)
pack.MinSyncedTicket = time.MaxTicket

d2 := document.New("c1", "d1")
d2 := document.New("d1")
err = d2.ApplyChangePack(pack)
assert.NoError(t, err)

Expand Down
14 changes: 3 additions & 11 deletions api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,14 @@ func FromChangePack(pbPack *api.ChangePack) (*change.Pack, error) {
}

return &change.Pack{
DocumentKey: FromDocumentKey(pbPack.DocumentKey),
DocumentKey: key.Key(pbPack.DocumentKey),
Checkpoint: fromCheckpoint(pbPack.Checkpoint),
Changes: changes,
Snapshot: pbPack.Snapshot,
MinSyncedTicket: minSyncedTicket,
}, nil
}

// FromDocumentKey converts the given Protobuf formats to model format.
func FromDocumentKey(pbKey *api.DocumentKey) key.Key {
return key.Key{
Collection: pbKey.Collection,
Document: pbKey.Document,
}
}

func fromCheckpoint(pbCheckpoint *api.Checkpoint) change.Checkpoint {
return change.NewCheckpoint(
pbCheckpoint.ServerSeq,
Expand Down Expand Up @@ -162,10 +154,10 @@ func fromChangeID(id *api.ChangeID) (change.ID, error) {
}

// FromDocumentKeys converts the given Protobuf formats to model format.
func FromDocumentKeys(pbKeys []*api.DocumentKey) []key.Key {
func FromDocumentKeys(pbKeys []string) []key.Key {
var keys []key.Key
for _, pbKey := range pbKeys {
keys = append(keys, FromDocumentKey(pbKey))
keys = append(keys, key.Key(pbKey))
}
return keys
}
Expand Down
20 changes: 6 additions & 14 deletions api/converter/to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func ToDocumentSummaries(summaries []*types.DocumentSummary) []*api.DocumentSumm
for _, summary := range summaries {
pbSummaries = append(pbSummaries, &api.DocumentSummary{
Id: summary.ID,
Key: ToDocumentKey(summary.Key),
Key: summary.Key.String(),
Snapshot: summary.Snapshot,
})
}
Expand Down Expand Up @@ -101,22 +101,14 @@ func ToChangePack(pack *change.Pack) (*api.ChangePack, error) {
}

return &api.ChangePack{
DocumentKey: ToDocumentKey(pack.DocumentKey),
DocumentKey: pack.DocumentKey.String(),
Checkpoint: ToCheckpoint(pack.Checkpoint),
Changes: pbChanges,
Snapshot: pack.Snapshot,
MinSyncedTicket: ToTimeTicket(pack.MinSyncedTicket),
}, nil
}

// ToDocumentKey converts the given model format to Protobuf format.
func ToDocumentKey(key key.Key) *api.DocumentKey {
return &api.DocumentKey{
Collection: key.Collection,
Document: key.Document,
}
}

// ToCheckpoint converts the given model format to Protobuf format.
func ToCheckpoint(cp change.Checkpoint) *api.Checkpoint {
return &api.Checkpoint{
Expand All @@ -136,12 +128,12 @@ func ToChangeID(id change.ID) *api.ChangeID {
}

// ToDocumentKeys converts the given model format to Protobuf format.
func ToDocumentKeys(keys []key.Key) []*api.DocumentKey {
var pbKeys []*api.DocumentKey
func ToDocumentKeys(keys []key.Key) []string {
var keyList []string
for _, k := range keys {
pbKeys = append(pbKeys, ToDocumentKey(k))
keyList = append(keyList, k.String())
}
return pbKeys
return keyList
}

// ToClientsMap converts the given model to Protobuf format.
Expand Down
Loading

0 comments on commit 149693a

Please sign in to comment.