aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-03-08 20:36:51 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-03-08 20:36:51 -0300
commit88dc315e454a695426becf928aef46668f9db0dc (patch)
tree2f4cfa8487c80bbbb5976e37bc955351b70cafa4 /lib
parente10acd09faf53c636b653c4df034716545db5fab (diff)
downloadSakura-88dc315e454a695426becf928aef46668f9db0dc.tar.gz
Sakura-88dc315e454a695426becf928aef46668f9db0dc.zip
server
Diffstat (limited to 'lib')
-rw-r--r--lib/management/database.ml8
-rw-r--r--lib/manipulation.ml7
-rw-r--r--lib/prelude/standard.ml33
3 files changed, 30 insertions, 18 deletions
diff --git a/lib/management/database.ml b/lib/management/database.ml
index e4705e5..08e03b8 100644
--- a/lib/management/database.ml
+++ b/lib/management/database.ml
@@ -72,7 +72,13 @@ let has_relation db name =
(** Add a relation to the database *)
let add_relation db ~(relation : Relation.t) =
- let relation_hash = Option.get relation.hash in
+ let relation_hash = match relation.hash with
+ | Some h -> h
+ | None ->
+ let tree = Option.value relation.tree ~default:Merkle.empty in
+ Hashing.hash_relation ~name:relation.name ~schema:relation.schema ~tree
+ in
+ let relation = { relation with hash = Some relation_hash } in
let tree = Merkle.insert relation_hash db.tree in
let relations = RelationMap.add relation.name relation db.relations in
update_state db ~relations ~tree
diff --git a/lib/manipulation.ml b/lib/manipulation.ml
index a1d90d6..5f7cfb9 100644
--- a/lib/manipulation.ml
+++ b/lib/manipulation.ml
@@ -770,9 +770,12 @@ module Make (Storage : Management.Physical.S) = struct
match store_relation storage relation with
| Error e -> Error e
| Ok () ->
- match store_database storage new_db with
+ match update_catalog_on_create storage new_db relation with
| Error e -> Error e
- | Ok () -> Ok (new_db, relation)
+ | Ok final_db ->
+ match store_database storage final_db with
+ | Error e -> Error e
+ | Ok () -> Ok (final_db, relation)
(** Remove a relation from the database.
Also removes its entries from [sakura:relation] and [sakura:attribute]. *)
diff --git a/lib/prelude/standard.ml b/lib/prelude/standard.ml
index aca7f93..efcb7ae 100644
--- a/lib/prelude/standard.ml
+++ b/lib/prelude/standard.ml
@@ -4,6 +4,9 @@
with both attributes in the same domain. The domain's [compare] function
is used for evaluation — no more spreading [Obj.magic]. *)
+(* Helper: wrap a native value in the Attribute.materialized record *)
+let mk v = { Attribute.value = Obj.repr v }
+
(* ============================================================================
Comparison relation factory
============================================================================ *)
@@ -66,7 +69,7 @@ let less_than_natural : Relation.t =
let left, right = pair_of_nat_lt position in
let attributes : Attribute.materialized Tuple.AttributeMap.t =
Tuple.AttributeMap.of_list
- [ ("left", Obj.magic left); ("right", Obj.magic right) ]
+ [ ("left", mk left); ("right", mk right) ]
in
Generator.Value
( Tuple.make_materialized ~relation:"less_than" ~attributes,
@@ -90,7 +93,7 @@ let less_than_or_equal_natural : Relation.t =
let right = max a b in
let attributes =
Tuple.AttributeMap.of_list
- [ ("left", Obj.magic left); ("right", Obj.magic right) ]
+ [ ("left", mk left); ("right", mk right) ]
in
Generator.Value
( Tuple.make_materialized ~relation:"less_than_or_equal" ~attributes,
@@ -110,7 +113,7 @@ let greater_than_natural : Relation.t =
(* Swap: right > left *)
let attributes =
Tuple.AttributeMap.of_list
- [ ("left", Obj.magic right); ("right", Obj.magic left) ]
+ [ ("left", mk right); ("right", mk left) ]
in
Generator.Value
( Tuple.make_materialized ~relation:"greater_than" ~attributes,
@@ -130,7 +133,7 @@ let greater_than_or_equal_natural : Relation.t =
let right = min a b in
let attributes =
Tuple.AttributeMap.of_list
- [ ("left", Obj.magic left); ("right", Obj.magic right) ]
+ [ ("left", mk left); ("right", mk right) ]
in
Generator.Value
( Tuple.make_materialized ~relation:"greater_than_or_equal" ~attributes,
@@ -148,7 +151,7 @@ let equal_natural : Relation.t =
| Some n ->
let attributes =
Tuple.AttributeMap.of_list
- [ ("left", Obj.magic n); ("right", Obj.magic n) ]
+ [ ("left", mk n); ("right", mk n) ]
in
Generator.Value
( Tuple.make_materialized ~relation:"equal" ~attributes, generator )
@@ -166,7 +169,7 @@ let not_equal_natural : Relation.t =
let left, right = if a = b then (a, b + 1) else (a, b) in
let attributes =
Tuple.AttributeMap.of_list
- [ ("left", Obj.magic left); ("right", Obj.magic right) ]
+ [ ("left", mk left); ("right", mk right) ]
in
Generator.Value
( Tuple.make_materialized ~relation:"not_equal" ~attributes, generator )
@@ -192,7 +195,7 @@ let plus_natural : Relation.t =
let s = a + b in
let attributes =
Tuple.AttributeMap.of_list
- [ ("a", Obj.magic a); ("b", Obj.magic b); ("sum", Obj.magic s) ]
+ [ ("a", mk a); ("b", mk b); ("sum", mk s) ]
in
Generator.Value
( Tuple.make_materialized ~relation:"plus" ~attributes, generator )
@@ -233,7 +236,7 @@ let times_natural : Relation.t =
let attributes =
Tuple.AttributeMap.of_list
[
- ("a", Obj.magic a); ("b", Obj.magic b); ("product", Obj.magic p);
+ ("a", mk a); ("b", mk b); ("product", mk p);
]
in
Generator.Value
@@ -276,9 +279,9 @@ let minus_natural : Relation.t =
let attributes =
Tuple.AttributeMap.of_list
[
- ("a", Obj.magic a);
- ("b", Obj.magic b);
- ("difference", Obj.magic diff);
+ ("a", mk a);
+ ("b", mk b);
+ ("difference", mk diff);
]
in
Generator.Value
@@ -327,10 +330,10 @@ let divide_natural : Relation.t =
let attributes =
Tuple.AttributeMap.of_list
[
- ("a", Obj.magic a);
- ("b", Obj.magic b);
- ("quotient", Obj.magic q);
- ("remainder", Obj.magic r);
+ ("a", mk a);
+ ("b", mk b);
+ ("quotient", mk q);
+ ("remainder", mk r);
]
in
Generator.Value