# Quick tutorial

Every single part of code block will be full example, so you can copy & paste it to play with it

## Insert / Save / Store

I want to store 100 objects in database

Status

• Autogenerated _id field
• Simple key-value

As you can see database usage is very easy. That was the simplest usage of CodernityDB.

## Get / Query

What if I would query database for x values ?

As you can see now we can get a record with given x value. And don't worry X index will be not affected with y assignments in 33-35 line.

Now you can run

print db.count(db.all, 'id')
print db.count(db.all, 'x')


As you expected, it will print you 200 and then 100 because only 100 records have x value, so they were indexed in X index

Status

• Possibility to query by x value.

## Duplicates

What if I have duplicate key values ?

As you can see database supports duplicate keys.

Warning

Using Hash index, you can't rely on record order, using :py:meth:~CodernityDB.database.Database.all or :py:meth:~CodernityDB.database.Database.get_many.

## Ordered data

OK, but I would to have them in order from range?

Status

• Possibility to get ordered values from given range

As you can see, it's not that hard. Just change the base from HashIndex to TreeBasedIndex.

## Update / Delete

Update is very easy, let's say you want to update all documents that have x % 5 == 0 and delete those with x % 7 == 0.

Isn't it easy ?

## Index functions

I would like to calculate some averages...

There are two ways to do it:

• Outside Database
• Inside Database

Using that function inside database will perform much better when you will use |CodernityDB-HTTP-link| because then calculations will be done server side. It will also allow you to reuse the same logic code in different places.

In that examples we assumed that t value is not stored in our X index.

Note

If you're |CodernityDB-HTTP-link| with |CodernityDB-PyClient-link| you should just change Database initialization (set host & port).

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.