Enable cars not to have color or keywords.
parent
5a2f17f7e0
commit
c4fce3c4a4
|
@ -8,8 +8,8 @@ class Car
|
||||||
include JSON::Serializable
|
include JSON::Serializable
|
||||||
|
|
||||||
property name : String # unique to each instance (1-1 relations)
|
property name : String # unique to each instance (1-1 relations)
|
||||||
property color : String # a simple attribute (1-n relations)
|
property color : String | DODB::NoIndex # a simple attribute (1-n relations)
|
||||||
property keywords : Array(String) # tags about a car, example: "shiny" (n-n relations)
|
property keywords : Array(String) | DODB::NoIndex # tags about a car, example: "shiny" (n-n relations)
|
||||||
|
|
||||||
def_clone
|
def_clone
|
||||||
|
|
||||||
|
@ -31,27 +31,27 @@ class Car
|
||||||
end
|
end
|
||||||
|
|
||||||
def ram_indexes(storage : DODB::Storage)
|
def ram_indexes(storage : DODB::Storage)
|
||||||
n = storage.new_RAM_index "name", &.name
|
n = storage.new_nilable_RAM_index "name", &.name
|
||||||
c = storage.new_RAM_partition "color", &.color
|
c = storage.new_nilable_RAM_partition "color", &.color
|
||||||
k = storage.new_RAM_tags "keyword", &.keywords
|
k = storage.new_nilable_RAM_tags "keyword", &.keywords
|
||||||
return n, c, k
|
return n, c, k
|
||||||
end
|
end
|
||||||
|
|
||||||
def cached_indexes(storage : DODB::Storage)
|
def cached_indexes(storage : DODB::Storage)
|
||||||
n = storage.new_index "name", &.name
|
n = storage.new_nilable_index "name", &.name
|
||||||
c = storage.new_partition "color", &.color
|
c = storage.new_nilable_partition "color", &.color
|
||||||
k = storage.new_tags "keyword", &.keywords
|
k = storage.new_nilable_tags "keyword", &.keywords
|
||||||
return n, c, k
|
return n, c, k
|
||||||
end
|
end
|
||||||
|
|
||||||
def uncached_indexes(storage : DODB::Storage)
|
def uncached_indexes(storage : DODB::Storage)
|
||||||
n = storage.new_uncached_index "name", &.name
|
n = storage.new_nilable_uncached_index "name", &.name
|
||||||
c = storage.new_uncached_partition "color", &.color
|
c = storage.new_nilable_uncached_partition "color", &.color
|
||||||
k = storage.new_uncached_tags "keyword", &.keywords
|
k = storage.new_nilable_uncached_tags "keyword", &.keywords
|
||||||
return n, c, k
|
return n, c, k
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_cars(storage : DODB::Storage, nb_iterations : Int32, from = 0)
|
def add_cars(storage : DODB::Storage, nb_iterations : Int32, from = 0, max_it_tags = 5000)
|
||||||
i = from
|
i = from
|
||||||
car1 = Car.new "Corvet", "red", [ "shiny", "impressive", "fast", "elegant" ]
|
car1 = Car.new "Corvet", "red", [ "shiny", "impressive", "fast", "elegant" ]
|
||||||
car2 = Car.new "Bullet-GT", "blue", [ "shiny", "fast", "expensive" ]
|
car2 = Car.new "Bullet-GT", "blue", [ "shiny", "fast", "expensive" ]
|
||||||
|
@ -66,11 +66,25 @@ def add_cars(storage : DODB::Storage, nb_iterations : Int32, from = 0)
|
||||||
car4.name = "Ford-5-#{i}"
|
car4.name = "Ford-5-#{i}"
|
||||||
car5.name = "C-MAX-#{i}"
|
car5.name = "C-MAX-#{i}"
|
||||||
|
|
||||||
storage << car1
|
if i >= max_it_tags
|
||||||
storage << car2
|
car1.color = DODB.no_index
|
||||||
storage << car3
|
car2.color = DODB.no_index
|
||||||
storage << car4
|
car3.color = DODB.no_index
|
||||||
storage << car5
|
car4.color = DODB.no_index
|
||||||
|
car5.color = DODB.no_index
|
||||||
|
|
||||||
|
car1.keywords = DODB.no_index
|
||||||
|
car2.keywords = DODB.no_index
|
||||||
|
car3.keywords = DODB.no_index
|
||||||
|
car4.keywords = DODB.no_index
|
||||||
|
car5.keywords = DODB.no_index
|
||||||
|
end
|
||||||
|
|
||||||
|
storage << car1.clone
|
||||||
|
storage << car2.clone
|
||||||
|
storage << car3.clone
|
||||||
|
storage << car4.clone
|
||||||
|
storage << car5.clone
|
||||||
i += 1
|
i += 1
|
||||||
#STDOUT.write "\radding value #{i}".to_slice
|
#STDOUT.write "\radding value #{i}".to_slice
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue