Skip to content
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

Refactor API #47

Merged
merged 17 commits into from Jan 16, 2022
Merged

Refactor API #47

merged 17 commits into from Jan 16, 2022

Conversation

kelindar
Copy link
Owner

@kelindar kelindar commented Jan 15, 2022

This PR introduces major breaking change in the API by removing the existing cursor and changing the way how the columns are accessed during transactions. Since columnar storage is intended to work on ranges of values, this speeds up range queries by around ~20-40%.

In order to access the results of the iteration, prior to calling Range() method, we need to first load column reader(s) we are going to need, using methods such as txn.String(), txn.Float64(), etc. These prepare read/write buffers necessary to perform efficient lookups while iterating.

In the example below we select all of the rogues from our collection and print out their name by using the Range() method and accessing the "name" column using a column reader which is created by calling txn.String("name") method.

players.Query(func(txn *Txn) error {
	names := txn.String("name") // Create a column reader

	return txn.With("rogue").Range(func(i uint32) {
		name, _ := names.Get()
		println("rogue name", name)
	})
})

Similarly, if you need to access more columns, you can simply create the appropriate column reader(s) and use them as shown in the example before.

players.Query(func(txn *Txn) error {
	names := txn.String("name")
	ages  := txn.Int64("age")

	return txn.With("rogue").Range(func(i uint32) {
		name, _ := names.Get()
		age,  _ := ages.Get()

		println("rogue name", name)
		println("rogue age", age)
	})
})

@kelindar kelindar changed the title WIP: Refactor API Refactor API Jan 16, 2022
@kelindar kelindar merged commit 02b2c66 into main Jan 16, 2022
@kelindar kelindar deleted the range branch January 16, 2022 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant