-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Document client interfaces in client/db.go #1305
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciate you taking the time to add documentation. LGTM, pointed some minor typos.
client/db.go
Outdated
@@ -19,30 +19,75 @@ import ( | |||
"github.com/sourcenetwork/defradb/events" | |||
) | |||
|
|||
// DB is the primary public programatic access point to the local Defra instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo:
// DB is the primary public programatic access point to the local Defra instance. | |
// DB is the primary public programmatic access point to the local Defra instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers :)
- programatic => programmatic
client/db.go
Outdated
@@ -19,30 +19,75 @@ import ( | |||
"github.com/sourcenetwork/defradb/events" | |||
) | |||
|
|||
// DB is the primary public programatic access point to the local Defra instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo:
// DB is the primary public programatic access point to the local Defra instance. | |
// DB is the primary public programatic access point to the local DefraDB instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it should be :)
- DefraDB (change all instances of this)
client/db.go
Outdated
@@ -19,30 +19,75 @@ import ( | |||
"github.com/sourcenetwork/defradb/events" | |||
) | |||
|
|||
// DB is the primary public programatic access point to the local Defra instance. | |||
// | |||
// It should be contructed via the [db] package, via the [db.NewDB] function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo:
// It should be contructed via the [db] package, via the [db.NewDB] function. | |
// It should be constructed via the [db] package, via the [db.NewDB] function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cheers
- contructed => constructed
client/db.go
Outdated
type DB interface { | ||
// Store contains Defra database functions protected by an internal, short-lived, transaction, allowing safe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo:
// Store contains Defra database functions protected by an internal, short-lived, transaction, allowing safe | |
// Store contains DefraDB functions protected by an internal, short-lived, transaction, allowing safe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
- Defra database => DefraDB
client/db.go
Outdated
// WithTxn returns a new [client.Store] that respects the given transaction. | ||
WithTxn(datastore.Txn) Store | ||
|
||
// Root returns the underlying root store, within which all data managed by Defra is held. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo:
// Root returns the underlying root store, within which all data managed by Defra is held. | |
// Root returns the underlying root store, within which all data managed by DefraDB is held. |
client/db.go
Outdated
Root() datastore.RootStore | ||
|
||
// Blockstore returns the blockstore, within which all blocks (commits) managed by Defra are held. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo:
// Blockstore returns the blockstore, within which all blocks (commits) managed by Defra are held. | |
// Blockstore returns the blockstore, within which all blocks (commits) managed by DefraDB are held. |
// It does not explicitly clear any data from persisted storage, and a new [DB] instance may typically | ||
// be created after calling this to resume operations on the prior data - this is however dependant on | ||
// the behaviour of the rootstore provided on database instance creation, as this function will Close | ||
// the provided rootstore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: idk if we care lol but I realize this is just American vs UK spelling diffs at this point.
// It does not explicitly clear any data from persisted storage, and a new [DB] instance may typically | |
// be created after calling this to resume operations on the prior data - this is however dependant on | |
// the behaviour of the rootstore provided on database instance creation, as this function will Close | |
// the provided rootstore. | |
// It does not explicitly clear any data from persisted storage, and a new [DB] instance may typically | |
// be created after calling this to resume operations on the prior data - this is however dependent on | |
// the behavior of the rootstore provided on database instance creation, as this function will Close | |
// the provided rootstore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://ruggedthuglife.com/canada/how-do-you-spell-behaviour-in-canada/ I'm fairly sure we never agreed to use US English, but I might be wrong.
https://www.merriam-webster.com/words-at-play/spelling-variants-dependent-vs-dependant also has similar issues :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UK English always. Not sure why Americans need to try to be special with everything...
// Events returns the database event queue. | ||
// | ||
// It may be used to monitor database events - a new event will be yielded for each mutation. | ||
// Note: it does not copy the queue, just the reference to it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: useful note
client/db.go
Outdated
PrintDump(ctx context.Context) error | ||
} | ||
|
||
// Store contains the core Defra read-write operations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo:
// Store contains the core Defra read-write operations. | |
// Store contains the core DefraDB read-write operations. |
cfe2c8f
to
35009e9
Compare
// All schema types provided must not exist prior to calling this, and they may not reference existing | ||
// types previously defined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought(out of scope): Reading this I realize that we should probably allow new schema to reference existing ones. For example, I may want to add an Image
schema that references the User
collection (images are owned by users).
// CreateCollection creates a new collection using the given description. | ||
// | ||
// WARNING: It does not currently update the GQL types, and as such a database restart is required after | ||
// calling this if use of the new collection via GQL is desired (for example via [ExecRequest]). | ||
CreateCollection(context.Context, CollectionDescription) (Collection, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
though: Seeing this warning makes me think that maybe this function shouldn't be exposed publicly. Unless I'm missing something, we don't use this function anywhere internally. We only use the private version of it for the adding schemas. It feels like giving users a chance to do something they may not want to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is still nominally useful, and my preference long term is to fix both this and UpdateCollection so that they do actually update the GQL types.
That said, I think the lack of references might be quite new - I think they were referenced until the client txn rework, but I'm not 100% sure.
I have just spotted that UpdateCollection is missing this warning and should have it too
- Add warning to UpdateCollection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove them until they do update the GQL types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont really think so, they will still work (on restart) and leaving them in documented like this should cause no harm IMO.
Can even be fixed in 0.5.1 if we want I think, as it wouldnt quite be a breaking change IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've merged, but happy to remove these if that is what we decide upon
client/db.go
Outdated
GQL GQLResult | ||
|
||
// Pub contains a pointer to an events stream which channels any subscription results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: Here I think events
should be singular event
as a stream implies multiple events coming one at a time. It's not a stream of events block.
Note: I don't have an english major so I may be wrong here but that is my interpretation of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cheers - will change
- events => event
Note: Upon writing this I do not actually think this function should close the rootstore, as Defra does not own it - it is an input parameter and should only be closed by the thing that created it.
Uses the existing internal documentation as a starting point, expands it and then backports the changes to the internal functions.
Note: I think the naming of this and its type is not ideal.
177b952
to
a52060f
Compare
Codecov Report
@@ Coverage Diff @@
## develop #1305 +/- ##
===========================================
- Coverage 70.47% 70.39% -0.08%
===========================================
Files 184 184
Lines 17825 17825
===========================================
- Hits 12562 12548 -14
- Misses 4311 4321 +10
- Partials 952 956 +4
|
* Document client.DB * Document client.DB.Store * Document client.DB.NewTxn functions * Document client.DB.Root * Document client.DB.Blockstore * Document client.DB.Close Note: Upon writing this I do not actually think this function should close the rootstore, as Defra does not own it - it is an input parameter and should only be closed by the thing that created it. * Document client.DB.Events * Document client.DB.MaxTxnRetries * Document client.DB.PrintDump * Document client.Store * Document client.Store.AddSchema Uses the existing internal documentation as a starting point, expands it and then backports the changes to the internal functions. * Document client.Store.CreateCollection * Document client.Store.GetCollectionByName * Document client.Store.GetCollectionBySchemaID * Document client.Store.GetCollectionByVersionID * Document client.Store.GetAllCollections * Document client.Store.ExecRequest * Document client.GQLResult * Document client.GQLResult.Errors * Document client.GQLResult.Data * Document client.RequestResult * Document client.RequestResult.GQL Note: I think the naming of this and its type is not ideal. * Document client.RequestResult.Pub * Remove commented out code
* Document client.DB * Document client.DB.Store * Document client.DB.NewTxn functions * Document client.DB.Root * Document client.DB.Blockstore * Document client.DB.Close Note: Upon writing this I do not actually think this function should close the rootstore, as Defra does not own it - it is an input parameter and should only be closed by the thing that created it. * Document client.DB.Events * Document client.DB.MaxTxnRetries * Document client.DB.PrintDump * Document client.Store * Document client.Store.AddSchema Uses the existing internal documentation as a starting point, expands it and then backports the changes to the internal functions. * Document client.Store.CreateCollection * Document client.Store.GetCollectionByName * Document client.Store.GetCollectionBySchemaID * Document client.Store.GetCollectionByVersionID * Document client.Store.GetAllCollections * Document client.Store.ExecRequest * Document client.GQLResult * Document client.GQLResult.Errors * Document client.GQLResult.Data * Document client.RequestResult * Document client.RequestResult.GQL Note: I think the naming of this and its type is not ideal. * Document client.RequestResult.Pub * Remove commented out code
Relevant issue(s)
Resolves #1303
Description
Adds basic documentation for the client interfaces in client/db.go.
Some oddities are noted in the commit message bodies, but I see changing them as out of scope - happy to tweak the easy ones here if people feel otherwise though.