toying-with-ramdb
Philippe PITTOLI 2024-05-15 14:39:33 +02:00
parent 1e6814f4db
commit 9a687a35cb
1 changed files with 39 additions and 26 deletions

View File

@ -1,4 +1,21 @@
.so macros.roff .so macros.roff
.de TREE1
.QP
.KS
.ft CW
.b1
.nf
..
.de TREE2
.ft
.fi
.b2
.KE
.QE
..
.
. \" The document starts here.
.
.TITLE Document Oriented DataBase (DODB) .TITLE Document Oriented DataBase (DODB)
.AUTHOR Philippe P. .AUTHOR Philippe P.
.ABSTRACT1 .ABSTRACT1
@ -156,15 +173,13 @@ Let's create a DODB database for our cars.
db = DODB::DataBase(Car).new "path/to/db-cars" db = DODB::DataBase(Car).new "path/to/db-cars"
# Adding an element to the db # Adding an element to the db
db << Car.new "Corvet GT", "red", ["elegant", "fast"] db << Car.new "Corvet", "red", ["elegant", "fast"]
# Reaching all objects in the db # Reaching all objects in the db
db.each do |car| db.each do |car|
pp! car pp! car
end end
.SOURCE .SOURCE
.SS Storing data
When a value is added, it is serialized\*[*] and written in a dedicated file. When a value is added, it is serialized\*[*] and written in a dedicated file.
.FOOTNOTE1 .FOOTNOTE1
Serialization is currently in JSON. Serialization is currently in JSON.
@ -172,32 +187,30 @@ CBOR is a work-in-progress.
Nothing binds DODB to a particular format. Nothing binds DODB to a particular format.
.FOOTNOTE2 .FOOTNOTE2
The key of the hash is a number, auto-incremented, used as the name of the stored file. The key of the hash is a number, auto-incremented, used as the name of the stored file.
The following example shows the content of the file system after adding three values. The following example shows the content of the file system after adding the first car.
.de TREE1
.QP
.KS
.ft CW
.b1
.nf
..
.de TREE2
.ft
.fi
.b2
.KE
.QE
..
.TREE1 .TREE1
$ tree storage/ $ tree db-cars/
storage db-cars/
`-- data |-- data
  +-- 0000000000 | `-- 0000000000 <- the first car in the database
  +-- 0000000001 `-- last-index
  `-- 0000000002
.TREE2 .TREE2
In this example, the directory In this example, the directory
.I storage/data .I db-cars/data
contains all three serialized values, with a formated number as their file name. contains the serialized value, with a formated number as file name.
The file "0000000000" contains the following:
.QP
.SOURCE JSON ps=10
{
"name": "Corvet",
"color": "red",
"keywords": [
"elegant",
"fast"
]
}
.SOURCE
.QE
.SS Indexes .SS Indexes
Database entries can be Database entries can be
.I indexed .I indexed