1. codernity
  2. CodernityDB


CodernityDB / docs / quick.rst

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


  • 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


  • Possibility to query by x value.


What if I have duplicate key values ?

As you can see database supports duplicate keys.


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?


  • 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

OK, cool, what about updates ?

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.


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

Tables, collections...?

OK, I got it, but can I store more than one data type in Database. Is there something like table or collection ?

Please refer to :ref:`tables_collections_q` for this task.