This PR fixes https://github.com/kelindar/column/issues/57 by checking the Insert() method and providing InsertKey(), UpsertKey(), QueryKey() and DeleteKey() methods that are specifically designed to deal with primary keys.
In addition, I've also improved the API for TTL management which is now a bit cleaner.
Here's an exerpt from the documentation on the primary keys:
Using Primary Keys
In certain cases it is useful to access a specific row by its primary key instead of an index which is generated internally by the collection. For such use-cases, the library provides Key column type that enables a seamless lookup by a user-defined primary key. In the example below we create a collection with a primary key name using CreateColumn() method with a ForKey() column type. Then, we use InsertKey() method to insert a value.
players := column.NewCollection()
players.CreateColumn("name", column.ForKey()) // Create a "name" as a primary-key
players.CreateColumn("class", column.ForString()) // .. and some other columns
// Insert a player with "merlin" as its primary key
c.InsertKey("merlin", func(r column.Row) error {
r.SetString("class", "mage")
return nil
})
Similarly, you can use primary key to query that data directly, without knowing the exact offset. Do note that using primary keys will have an overhead, as it requires an additional step of looking up the offset using a hash table managed internally.
This PR fixes https://github.com/kelindar/column/issues/57 by checking the
Insert()
method and providingInsertKey()
,UpsertKey()
,QueryKey()
andDeleteKey()
methods that are specifically designed to deal with primary keys.In addition, I've also improved the API for
TTL
management which is now a bit cleaner.Here's an exerpt from the documentation on the primary keys:
Using Primary Keys
In certain cases it is useful to access a specific row by its primary key instead of an index which is generated internally by the collection. For such use-cases, the library provides
Key
column type that enables a seamless lookup by a user-defined primary key. In the example below we create a collection with a primary keyname
usingCreateColumn()
method with aForKey()
column type. Then, we useInsertKey()
method to insert a value.Similarly, you can use primary key to query that data directly, without knowing the exact offset. Do note that using primary keys will have an overhead, as it requires an additional step of looking up the offset using a hash table managed internally.