From 2284da9f003f2eacceaa5d89280675138d61dbe0 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 18:41:57 -0300 Subject: [PATCH 01/32] update --- bindings/julia/src/PSRDatabase.jl | 1 + bindings/julia/src/database.jl | 20 -------------------- bindings/julia/src/database_create.jl | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 bindings/julia/src/database_create.jl diff --git a/bindings/julia/src/PSRDatabase.jl b/bindings/julia/src/PSRDatabase.jl index e468d24..03d5b01 100644 --- a/bindings/julia/src/PSRDatabase.jl +++ b/bindings/julia/src/PSRDatabase.jl @@ -6,6 +6,7 @@ import .C include("exceptions.jl") include("element.jl") include("database.jl") +include("database_create.jl") include("lua_runner.jl") export Element, Database, LuaRunner, DatabaseException diff --git a/bindings/julia/src/database.jl b/bindings/julia/src/database.jl index f84864d..8162786 100644 --- a/bindings/julia/src/database.jl +++ b/bindings/julia/src/database.jl @@ -26,26 +26,6 @@ function from_migrations(db_path, migrations_path) return Database(ptr) end -function create_element!(db::Database, collection::String, e::Element) - if C.psr_database_create_element(db.ptr, collection, e.ptr) == -1 - throw(DatabaseException("Failed to create element in collection $collection")) - end - return nothing -end - -function create_element!(db::Database, collection::String; kwargs...) - e = Element() - for (k, v) in kwargs - e[String(k)] = v - end - try - create_element!(db, collection, e) - finally - destroy!(e) - end - return nothing -end - function close!(db::Database) if db.ptr != C_NULL C.psr_database_close(db.ptr) diff --git a/bindings/julia/src/database_create.jl b/bindings/julia/src/database_create.jl new file mode 100644 index 0000000..d3a3581 --- /dev/null +++ b/bindings/julia/src/database_create.jl @@ -0,0 +1,19 @@ +function create_element!(db::Database, collection::String, e::Element) + if C.psr_database_create_element(db.ptr, collection, e.ptr) == -1 + throw(DatabaseException("Failed to create element in collection $collection")) + end + return nothing +end + +function create_element!(db::Database, collection::String; kwargs...) + e = Element() + for (k, v) in kwargs + e[String(k)] = v + end + try + create_element!(db, collection, e) + finally + destroy!(e) + end + return nothing +end From bdec737c8de23ed7ea181b9024108fac668bd4f8 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 18:45:46 -0300 Subject: [PATCH 02/32] update --- bindings/julia/src/PSRDatabase.jl | 3 + bindings/julia/src/database.jl | 476 -------------------------- bindings/julia/src/database_create.jl | 14 + bindings/julia/src/database_delete.jl | 7 + bindings/julia/src/database_read.jl | 461 +++++++++++++++++++++++++ bindings/julia/src/database_update.jl | 149 ++++++++ 6 files changed, 634 insertions(+), 476 deletions(-) create mode 100644 bindings/julia/src/database_delete.jl create mode 100644 bindings/julia/src/database_read.jl create mode 100644 bindings/julia/src/database_update.jl diff --git a/bindings/julia/src/PSRDatabase.jl b/bindings/julia/src/PSRDatabase.jl index 03d5b01..5cdeb30 100644 --- a/bindings/julia/src/PSRDatabase.jl +++ b/bindings/julia/src/PSRDatabase.jl @@ -7,6 +7,9 @@ include("exceptions.jl") include("element.jl") include("database.jl") include("database_create.jl") +include("database_read.jl") +include("database_update.jl") +include("database_delete.jl") include("lua_runner.jl") export Element, Database, LuaRunner, DatabaseException diff --git a/bindings/julia/src/database.jl b/bindings/julia/src/database.jl index 8162786..3d069b8 100644 --- a/bindings/julia/src/database.jl +++ b/bindings/julia/src/database.jl @@ -34,482 +34,6 @@ function close!(db::Database) return nothing end -function set_scalar_relation!( - db::Database, - collection::String, - attribute::String, - from_label::String, - to_label::String, -) - err = C.psr_database_set_scalar_relation(db.ptr, collection, attribute, from_label, to_label) - if err != C.PSR_OK - throw(DatabaseException("Failed to set scalar relation '$attribute' in '$collection'")) - end - return nothing -end - -function read_scalar_relation(db::Database, collection::String, attribute::String) - out_values = Ref{Ptr{Ptr{Cchar}}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_scalar_relation(db.ptr, collection, attribute, out_values, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read scalar relation '$attribute' from '$collection'")) - end - - count = out_count[] - if count == 0 || out_values[] == C_NULL - return Union{String, Nothing}[] - end - - ptrs = unsafe_wrap(Array, out_values[], count) - result = Union{String, Nothing}[] - for ptr in ptrs - if ptr == C_NULL - push!(result, nothing) - else - s = unsafe_string(ptr) - push!(result, isempty(s) ? nothing : s) - end - end - C.psr_free_string_array(out_values[], count) - return result -end - -function read_scalar_integers(db::Database, collection::String, attribute::String) - out_values = Ref{Ptr{Int64}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_scalar_integers(db.ptr, collection, attribute, out_values, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read scalar integers from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_values[] == C_NULL - return Int64[] - end - - result = unsafe_wrap(Array, out_values[], count) |> copy - C.psr_free_int_array(out_values[]) - return result -end - -function read_scalar_doubles(db::Database, collection::String, attribute::String) - out_values = Ref{Ptr{Float64}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_scalar_doubles(db.ptr, collection, attribute, out_values, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read scalar doubles from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_values[] == C_NULL - return Float64[] - end - - result = unsafe_wrap(Array, out_values[], count) |> copy - C.psr_free_double_array(out_values[]) - return result -end - -function read_scalar_strings(db::Database, collection::String, attribute::String) - out_values = Ref{Ptr{Ptr{Cchar}}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_scalar_strings(db.ptr, collection, attribute, out_values, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read scalar strings from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_values[] == C_NULL - return String[] - end - - ptrs = unsafe_wrap(Array, out_values[], count) - result = [unsafe_string(ptr) for ptr in ptrs] - C.psr_free_string_array(out_values[], count) - return result -end - -function read_vector_integers(db::Database, collection::String, attribute::String) - out_vectors = Ref{Ptr{Ptr{Int64}}}(C_NULL) - out_sizes = Ref{Ptr{Csize_t}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_vector_integers(db.ptr, collection, attribute, out_vectors, out_sizes, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read vector integers from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_vectors[] == C_NULL - return Vector{Int64}[] - end - - vectors_ptr = unsafe_wrap(Array, out_vectors[], count) - sizes_ptr = unsafe_wrap(Array, out_sizes[], count) - result = Vector{Int64}[] - for i in 1:count - if vectors_ptr[i] == C_NULL || sizes_ptr[i] == 0 - push!(result, Int64[]) - else - push!(result, copy(unsafe_wrap(Array, vectors_ptr[i], sizes_ptr[i]))) - end - end - C.psr_free_int_vectors(out_vectors[], out_sizes[], count) - return result -end - -function read_vector_doubles(db::Database, collection::String, attribute::String) - out_vectors = Ref{Ptr{Ptr{Cdouble}}}(C_NULL) - out_sizes = Ref{Ptr{Csize_t}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_vector_doubles(db.ptr, collection, attribute, out_vectors, out_sizes, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read vector doubles from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_vectors[] == C_NULL - return Vector{Float64}[] - end - - vectors_ptr = unsafe_wrap(Array, out_vectors[], count) - sizes_ptr = unsafe_wrap(Array, out_sizes[], count) - result = Vector{Float64}[] - for i in 1:count - if vectors_ptr[i] == C_NULL || sizes_ptr[i] == 0 - push!(result, Float64[]) - else - push!(result, copy(unsafe_wrap(Array, vectors_ptr[i], sizes_ptr[i]))) - end - end - C.psr_free_double_vectors(out_vectors[], out_sizes[], count) - return result -end - -function read_vector_strings(db::Database, collection::String, attribute::String) - out_vectors = Ref{Ptr{Ptr{Ptr{Cchar}}}}(C_NULL) - out_sizes = Ref{Ptr{Csize_t}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_vector_strings(db.ptr, collection, attribute, out_vectors, out_sizes, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read vector strings from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_vectors[] == C_NULL - return Vector{String}[] - end - - vectors_ptr = unsafe_wrap(Array, out_vectors[], count) - sizes_ptr = unsafe_wrap(Array, out_sizes[], count) - result = Vector{String}[] - for i in 1:count - if vectors_ptr[i] == C_NULL || sizes_ptr[i] == 0 - push!(result, String[]) - else - str_ptrs = unsafe_wrap(Array, vectors_ptr[i], sizes_ptr[i]) - push!(result, [unsafe_string(ptr) for ptr in str_ptrs]) - end - end - C.psr_free_string_vectors(out_vectors[], out_sizes[], count) - return result -end - -function read_set_integers(db::Database, collection::String, attribute::String) - out_sets = Ref{Ptr{Ptr{Int64}}}(C_NULL) - out_sizes = Ref{Ptr{Csize_t}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_set_integers(db.ptr, collection, attribute, out_sets, out_sizes, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read set integers from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_sets[] == C_NULL - return Vector{Int64}[] - end - - sets_ptr = unsafe_wrap(Array, out_sets[], count) - sizes_ptr = unsafe_wrap(Array, out_sizes[], count) - result = Vector{Int64}[] - for i in 1:count - if sets_ptr[i] == C_NULL || sizes_ptr[i] == 0 - push!(result, Int64[]) - else - push!(result, copy(unsafe_wrap(Array, sets_ptr[i], sizes_ptr[i]))) - end - end - C.psr_free_int_vectors(out_sets[], out_sizes[], count) - return result -end - -function read_set_doubles(db::Database, collection::String, attribute::String) - out_sets = Ref{Ptr{Ptr{Cdouble}}}(C_NULL) - out_sizes = Ref{Ptr{Csize_t}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_set_doubles(db.ptr, collection, attribute, out_sets, out_sizes, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read set doubles from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_sets[] == C_NULL - return Vector{Float64}[] - end - - sets_ptr = unsafe_wrap(Array, out_sets[], count) - sizes_ptr = unsafe_wrap(Array, out_sizes[], count) - result = Vector{Float64}[] - for i in 1:count - if sets_ptr[i] == C_NULL || sizes_ptr[i] == 0 - push!(result, Float64[]) - else - push!(result, copy(unsafe_wrap(Array, sets_ptr[i], sizes_ptr[i]))) - end - end - C.psr_free_double_vectors(out_sets[], out_sizes[], count) - return result -end - -function read_set_strings(db::Database, collection::String, attribute::String) - out_sets = Ref{Ptr{Ptr{Ptr{Cchar}}}}(C_NULL) - out_sizes = Ref{Ptr{Csize_t}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_set_strings(db.ptr, collection, attribute, out_sets, out_sizes, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read set strings from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_sets[] == C_NULL - return Vector{String}[] - end - - sets_ptr = unsafe_wrap(Array, out_sets[], count) - sizes_ptr = unsafe_wrap(Array, out_sizes[], count) - result = Vector{String}[] - for i in 1:count - if sets_ptr[i] == C_NULL || sizes_ptr[i] == 0 - push!(result, String[]) - else - str_ptrs = unsafe_wrap(Array, sets_ptr[i], sizes_ptr[i]) - push!(result, [unsafe_string(ptr) for ptr in str_ptrs]) - end - end - C.psr_free_string_vectors(out_sets[], out_sizes[], count) - return result -end - -# Read scalar by ID functions - -function read_scalar_integers_by_id(db::Database, collection::String, attribute::String, id::Int64) - out_value = Ref{Int64}(0) - out_has_value = Ref{Cint}(0) - - err = C.psr_database_read_scalar_integers_by_id(db.ptr, collection, attribute, id, out_value, out_has_value) - if err != C.PSR_OK - throw(DatabaseException("Failed to read scalar integer by id from '$collection.$attribute'")) - end - - if out_has_value[] == 0 - return nothing - end - return out_value[] -end - -function read_scalar_doubles_by_id(db::Database, collection::String, attribute::String, id::Int64) - out_value = Ref{Float64}(0.0) - out_has_value = Ref{Cint}(0) - - err = C.psr_database_read_scalar_doubles_by_id(db.ptr, collection, attribute, id, out_value, out_has_value) - if err != C.PSR_OK - throw(DatabaseException("Failed to read scalar double by id from '$collection.$attribute'")) - end - - if out_has_value[] == 0 - return nothing - end - return out_value[] -end - -function read_scalar_strings_by_id(db::Database, collection::String, attribute::String, id::Int64) - out_value = Ref{Ptr{Cchar}}(C_NULL) - out_has_value = Ref{Cint}(0) - - err = C.psr_database_read_scalar_strings_by_id(db.ptr, collection, attribute, id, out_value, out_has_value) - if err != C.PSR_OK - throw(DatabaseException("Failed to read scalar string by id from '$collection.$attribute'")) - end - - if out_has_value[] == 0 || out_value[] == C_NULL - return nothing - end - result = unsafe_string(out_value[]) - C.psr_string_free(out_value[]) - return result -end - -# Read vector by ID functions - -function read_vector_integers_by_id(db::Database, collection::String, attribute::String, id::Int64) - out_values = Ref{Ptr{Int64}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_vector_integers_by_id(db.ptr, collection, attribute, id, out_values, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read vector integers by id from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_values[] == C_NULL - return Int64[] - end - - result = unsafe_wrap(Array, out_values[], count) |> copy - C.psr_free_int_array(out_values[]) - return result -end - -function read_vector_doubles_by_id(db::Database, collection::String, attribute::String, id::Int64) - out_values = Ref{Ptr{Float64}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_vector_doubles_by_id(db.ptr, collection, attribute, id, out_values, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read vector doubles by id from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_values[] == C_NULL - return Float64[] - end - - result = unsafe_wrap(Array, out_values[], count) |> copy - C.psr_free_double_array(out_values[]) - return result -end - -function read_vector_strings_by_id(db::Database, collection::String, attribute::String, id::Int64) - out_values = Ref{Ptr{Ptr{Cchar}}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_vector_strings_by_id(db.ptr, collection, attribute, id, out_values, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read vector strings by id from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_values[] == C_NULL - return String[] - end - - ptrs = unsafe_wrap(Array, out_values[], count) - result = [unsafe_string(ptr) for ptr in ptrs] - C.psr_free_string_array(out_values[], count) - return result -end - -# Read set by ID functions - -function read_set_integers_by_id(db::Database, collection::String, attribute::String, id::Int64) - out_values = Ref{Ptr{Int64}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_set_integers_by_id(db.ptr, collection, attribute, id, out_values, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read set integers by id from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_values[] == C_NULL - return Int64[] - end - - result = unsafe_wrap(Array, out_values[], count) |> copy - C.psr_free_int_array(out_values[]) - return result -end - -function read_set_doubles_by_id(db::Database, collection::String, attribute::String, id::Int64) - out_values = Ref{Ptr{Float64}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_set_doubles_by_id(db.ptr, collection, attribute, id, out_values, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read set doubles by id from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_values[] == C_NULL - return Float64[] - end - - result = unsafe_wrap(Array, out_values[], count) |> copy - C.psr_free_double_array(out_values[]) - return result -end - -function read_set_strings_by_id(db::Database, collection::String, attribute::String, id::Int64) - out_values = Ref{Ptr{Ptr{Cchar}}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_set_strings_by_id(db.ptr, collection, attribute, id, out_values, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read set strings by id from '$collection.$attribute'")) - end - - count = out_count[] - if count == 0 || out_values[] == C_NULL - return String[] - end - - ptrs = unsafe_wrap(Array, out_values[], count) - result = [unsafe_string(ptr) for ptr in ptrs] - C.psr_free_string_array(out_values[], count) - return result -end - -function read_element_ids(db::Database, collection::String) - out_ids = Ref{Ptr{Int64}}(C_NULL) - out_count = Ref{Csize_t}(0) - - err = C.psr_database_read_element_ids(db.ptr, collection, out_ids, out_count) - if err != C.PSR_OK - throw(DatabaseException("Failed to read element ids from '$collection'")) - end - - count = out_count[] - if count == 0 || out_ids[] == C_NULL - return Int64[] - end - - result = unsafe_wrap(Array, out_ids[], count) |> copy - C.psr_free_int_array(out_ids[]) - return result -end - -function get_attribute_type(db::Database, collection::String, attribute::String) - out_data_structure = Ref{C.psr_data_structure_t}(C.PSR_DATA_STRUCTURE_SCALAR) - out_data_type = Ref{C.psr_data_type_t}(C.PSR_DATA_TYPE_INTEGER) - - err = C.psr_database_get_attribute_type(db.ptr, collection, attribute, out_data_structure, out_data_type) - if err != C.PSR_OK - throw(DatabaseException("Failed to get attribute type for '$collection.$attribute'")) - end - - return (data_structure = out_data_structure[], data_type = out_data_type[]) -end - function delete_element_by_id!(db::Database, collection::String, id::Int64) err = C.psr_database_delete_element_by_id(db.ptr, collection, id) if err != C.PSR_OK diff --git a/bindings/julia/src/database_create.jl b/bindings/julia/src/database_create.jl index d3a3581..8616bc4 100644 --- a/bindings/julia/src/database_create.jl +++ b/bindings/julia/src/database_create.jl @@ -17,3 +17,17 @@ function create_element!(db::Database, collection::String; kwargs...) end return nothing end + +function set_scalar_relation!( + db::Database, + collection::String, + attribute::String, + from_label::String, + to_label::String, +) + err = C.psr_database_set_scalar_relation(db.ptr, collection, attribute, from_label, to_label) + if err != C.PSR_OK + throw(DatabaseException("Failed to set scalar relation '$attribute' in '$collection'")) + end + return nothing +end \ No newline at end of file diff --git a/bindings/julia/src/database_delete.jl b/bindings/julia/src/database_delete.jl new file mode 100644 index 0000000..557af19 --- /dev/null +++ b/bindings/julia/src/database_delete.jl @@ -0,0 +1,7 @@ +function delete_element_by_id!(db::Database, collection::String, id::Int64) + err = C.psr_database_delete_element_by_id(db.ptr, collection, id) + if err != C.PSR_OK + throw(DatabaseException("Failed to delete element $id from '$collection'")) + end + return nothing +end diff --git a/bindings/julia/src/database_read.jl b/bindings/julia/src/database_read.jl new file mode 100644 index 0000000..ed4f634 --- /dev/null +++ b/bindings/julia/src/database_read.jl @@ -0,0 +1,461 @@ +function read_scalar_relation(db::Database, collection::String, attribute::String) + out_values = Ref{Ptr{Ptr{Cchar}}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_scalar_relation(db.ptr, collection, attribute, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read scalar relation '$attribute' from '$collection'")) + end + + count = out_count[] + if count == 0 || out_values[] == C_NULL + return Union{String, Nothing}[] + end + + ptrs = unsafe_wrap(Array, out_values[], count) + result = Union{String, Nothing}[] + for ptr in ptrs + if ptr == C_NULL + push!(result, nothing) + else + s = unsafe_string(ptr) + push!(result, isempty(s) ? nothing : s) + end + end + C.psr_free_string_array(out_values[], count) + return result +end + +function read_scalar_integers(db::Database, collection::String, attribute::String) + out_values = Ref{Ptr{Int64}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_scalar_integers(db.ptr, collection, attribute, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read scalar integers from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_values[] == C_NULL + return Int64[] + end + + result = unsafe_wrap(Array, out_values[], count) |> copy + C.psr_free_int_array(out_values[]) + return result +end + +function read_scalar_doubles(db::Database, collection::String, attribute::String) + out_values = Ref{Ptr{Float64}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_scalar_doubles(db.ptr, collection, attribute, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read scalar doubles from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_values[] == C_NULL + return Float64[] + end + + result = unsafe_wrap(Array, out_values[], count) |> copy + C.psr_free_double_array(out_values[]) + return result +end + +function read_scalar_strings(db::Database, collection::String, attribute::String) + out_values = Ref{Ptr{Ptr{Cchar}}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_scalar_strings(db.ptr, collection, attribute, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read scalar strings from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_values[] == C_NULL + return String[] + end + + ptrs = unsafe_wrap(Array, out_values[], count) + result = [unsafe_string(ptr) for ptr in ptrs] + C.psr_free_string_array(out_values[], count) + return result +end + +function read_vector_integers(db::Database, collection::String, attribute::String) + out_vectors = Ref{Ptr{Ptr{Int64}}}(C_NULL) + out_sizes = Ref{Ptr{Csize_t}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_vector_integers(db.ptr, collection, attribute, out_vectors, out_sizes, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read vector integers from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_vectors[] == C_NULL + return Vector{Int64}[] + end + + vectors_ptr = unsafe_wrap(Array, out_vectors[], count) + sizes_ptr = unsafe_wrap(Array, out_sizes[], count) + result = Vector{Int64}[] + for i in 1:count + if vectors_ptr[i] == C_NULL || sizes_ptr[i] == 0 + push!(result, Int64[]) + else + push!(result, copy(unsafe_wrap(Array, vectors_ptr[i], sizes_ptr[i]))) + end + end + C.psr_free_int_vectors(out_vectors[], out_sizes[], count) + return result +end + +function read_vector_doubles(db::Database, collection::String, attribute::String) + out_vectors = Ref{Ptr{Ptr{Cdouble}}}(C_NULL) + out_sizes = Ref{Ptr{Csize_t}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_vector_doubles(db.ptr, collection, attribute, out_vectors, out_sizes, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read vector doubles from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_vectors[] == C_NULL + return Vector{Float64}[] + end + + vectors_ptr = unsafe_wrap(Array, out_vectors[], count) + sizes_ptr = unsafe_wrap(Array, out_sizes[], count) + result = Vector{Float64}[] + for i in 1:count + if vectors_ptr[i] == C_NULL || sizes_ptr[i] == 0 + push!(result, Float64[]) + else + push!(result, copy(unsafe_wrap(Array, vectors_ptr[i], sizes_ptr[i]))) + end + end + C.psr_free_double_vectors(out_vectors[], out_sizes[], count) + return result +end + +function read_vector_strings(db::Database, collection::String, attribute::String) + out_vectors = Ref{Ptr{Ptr{Ptr{Cchar}}}}(C_NULL) + out_sizes = Ref{Ptr{Csize_t}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_vector_strings(db.ptr, collection, attribute, out_vectors, out_sizes, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read vector strings from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_vectors[] == C_NULL + return Vector{String}[] + end + + vectors_ptr = unsafe_wrap(Array, out_vectors[], count) + sizes_ptr = unsafe_wrap(Array, out_sizes[], count) + result = Vector{String}[] + for i in 1:count + if vectors_ptr[i] == C_NULL || sizes_ptr[i] == 0 + push!(result, String[]) + else + str_ptrs = unsafe_wrap(Array, vectors_ptr[i], sizes_ptr[i]) + push!(result, [unsafe_string(ptr) for ptr in str_ptrs]) + end + end + C.psr_free_string_vectors(out_vectors[], out_sizes[], count) + return result +end + +function read_set_integers(db::Database, collection::String, attribute::String) + out_sets = Ref{Ptr{Ptr{Int64}}}(C_NULL) + out_sizes = Ref{Ptr{Csize_t}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_set_integers(db.ptr, collection, attribute, out_sets, out_sizes, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read set integers from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_sets[] == C_NULL + return Vector{Int64}[] + end + + sets_ptr = unsafe_wrap(Array, out_sets[], count) + sizes_ptr = unsafe_wrap(Array, out_sizes[], count) + result = Vector{Int64}[] + for i in 1:count + if sets_ptr[i] == C_NULL || sizes_ptr[i] == 0 + push!(result, Int64[]) + else + push!(result, copy(unsafe_wrap(Array, sets_ptr[i], sizes_ptr[i]))) + end + end + C.psr_free_int_vectors(out_sets[], out_sizes[], count) + return result +end + +function read_set_doubles(db::Database, collection::String, attribute::String) + out_sets = Ref{Ptr{Ptr{Cdouble}}}(C_NULL) + out_sizes = Ref{Ptr{Csize_t}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_set_doubles(db.ptr, collection, attribute, out_sets, out_sizes, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read set doubles from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_sets[] == C_NULL + return Vector{Float64}[] + end + + sets_ptr = unsafe_wrap(Array, out_sets[], count) + sizes_ptr = unsafe_wrap(Array, out_sizes[], count) + result = Vector{Float64}[] + for i in 1:count + if sets_ptr[i] == C_NULL || sizes_ptr[i] == 0 + push!(result, Float64[]) + else + push!(result, copy(unsafe_wrap(Array, sets_ptr[i], sizes_ptr[i]))) + end + end + C.psr_free_double_vectors(out_sets[], out_sizes[], count) + return result +end + +function read_set_strings(db::Database, collection::String, attribute::String) + out_sets = Ref{Ptr{Ptr{Ptr{Cchar}}}}(C_NULL) + out_sizes = Ref{Ptr{Csize_t}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_set_strings(db.ptr, collection, attribute, out_sets, out_sizes, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read set strings from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_sets[] == C_NULL + return Vector{String}[] + end + + sets_ptr = unsafe_wrap(Array, out_sets[], count) + sizes_ptr = unsafe_wrap(Array, out_sizes[], count) + result = Vector{String}[] + for i in 1:count + if sets_ptr[i] == C_NULL || sizes_ptr[i] == 0 + push!(result, String[]) + else + str_ptrs = unsafe_wrap(Array, sets_ptr[i], sizes_ptr[i]) + push!(result, [unsafe_string(ptr) for ptr in str_ptrs]) + end + end + C.psr_free_string_vectors(out_sets[], out_sizes[], count) + return result +end + +# Read scalar by ID functions + +function read_scalar_integers_by_id(db::Database, collection::String, attribute::String, id::Int64) + out_value = Ref{Int64}(0) + out_has_value = Ref{Cint}(0) + + err = C.psr_database_read_scalar_integers_by_id(db.ptr, collection, attribute, id, out_value, out_has_value) + if err != C.PSR_OK + throw(DatabaseException("Failed to read scalar integer by id from '$collection.$attribute'")) + end + + if out_has_value[] == 0 + return nothing + end + return out_value[] +end + +function read_scalar_doubles_by_id(db::Database, collection::String, attribute::String, id::Int64) + out_value = Ref{Float64}(0.0) + out_has_value = Ref{Cint}(0) + + err = C.psr_database_read_scalar_doubles_by_id(db.ptr, collection, attribute, id, out_value, out_has_value) + if err != C.PSR_OK + throw(DatabaseException("Failed to read scalar double by id from '$collection.$attribute'")) + end + + if out_has_value[] == 0 + return nothing + end + return out_value[] +end + +function read_scalar_strings_by_id(db::Database, collection::String, attribute::String, id::Int64) + out_value = Ref{Ptr{Cchar}}(C_NULL) + out_has_value = Ref{Cint}(0) + + err = C.psr_database_read_scalar_strings_by_id(db.ptr, collection, attribute, id, out_value, out_has_value) + if err != C.PSR_OK + throw(DatabaseException("Failed to read scalar string by id from '$collection.$attribute'")) + end + + if out_has_value[] == 0 || out_value[] == C_NULL + return nothing + end + result = unsafe_string(out_value[]) + C.psr_string_free(out_value[]) + return result +end + +# Read vector by ID functions + +function read_vector_integers_by_id(db::Database, collection::String, attribute::String, id::Int64) + out_values = Ref{Ptr{Int64}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_vector_integers_by_id(db.ptr, collection, attribute, id, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read vector integers by id from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_values[] == C_NULL + return Int64[] + end + + result = unsafe_wrap(Array, out_values[], count) |> copy + C.psr_free_int_array(out_values[]) + return result +end + +function read_vector_doubles_by_id(db::Database, collection::String, attribute::String, id::Int64) + out_values = Ref{Ptr{Float64}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_vector_doubles_by_id(db.ptr, collection, attribute, id, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read vector doubles by id from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_values[] == C_NULL + return Float64[] + end + + result = unsafe_wrap(Array, out_values[], count) |> copy + C.psr_free_double_array(out_values[]) + return result +end + +function read_vector_strings_by_id(db::Database, collection::String, attribute::String, id::Int64) + out_values = Ref{Ptr{Ptr{Cchar}}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_vector_strings_by_id(db.ptr, collection, attribute, id, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read vector strings by id from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_values[] == C_NULL + return String[] + end + + ptrs = unsafe_wrap(Array, out_values[], count) + result = [unsafe_string(ptr) for ptr in ptrs] + C.psr_free_string_array(out_values[], count) + return result +end + +# Read set by ID functions + +function read_set_integers_by_id(db::Database, collection::String, attribute::String, id::Int64) + out_values = Ref{Ptr{Int64}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_set_integers_by_id(db.ptr, collection, attribute, id, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read set integers by id from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_values[] == C_NULL + return Int64[] + end + + result = unsafe_wrap(Array, out_values[], count) |> copy + C.psr_free_int_array(out_values[]) + return result +end + +function read_set_doubles_by_id(db::Database, collection::String, attribute::String, id::Int64) + out_values = Ref{Ptr{Float64}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_set_doubles_by_id(db.ptr, collection, attribute, id, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read set doubles by id from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_values[] == C_NULL + return Float64[] + end + + result = unsafe_wrap(Array, out_values[], count) |> copy + C.psr_free_double_array(out_values[]) + return result +end + +function read_set_strings_by_id(db::Database, collection::String, attribute::String, id::Int64) + out_values = Ref{Ptr{Ptr{Cchar}}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_set_strings_by_id(db.ptr, collection, attribute, id, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read set strings by id from '$collection.$attribute'")) + end + + count = out_count[] + if count == 0 || out_values[] == C_NULL + return String[] + end + + ptrs = unsafe_wrap(Array, out_values[], count) + result = [unsafe_string(ptr) for ptr in ptrs] + C.psr_free_string_array(out_values[], count) + return result +end + +function read_element_ids(db::Database, collection::String) + out_ids = Ref{Ptr{Int64}}(C_NULL) + out_count = Ref{Csize_t}(0) + + err = C.psr_database_read_element_ids(db.ptr, collection, out_ids, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read element ids from '$collection'")) + end + + count = out_count[] + if count == 0 || out_ids[] == C_NULL + return Int64[] + end + + result = unsafe_wrap(Array, out_ids[], count) |> copy + C.psr_free_int_array(out_ids[]) + return result +end + +function get_attribute_type(db::Database, collection::String, attribute::String) + out_data_structure = Ref{C.psr_data_structure_t}(C.PSR_DATA_STRUCTURE_SCALAR) + out_data_type = Ref{C.psr_data_type_t}(C.PSR_DATA_TYPE_INTEGER) + + err = C.psr_database_get_attribute_type(db.ptr, collection, attribute, out_data_structure, out_data_type) + if err != C.PSR_OK + throw(DatabaseException("Failed to get attribute type for '$collection.$attribute'")) + end + + return (data_structure = out_data_structure[], data_type = out_data_type[]) +end diff --git a/bindings/julia/src/database_update.jl b/bindings/julia/src/database_update.jl new file mode 100644 index 0000000..e0c164e --- /dev/null +++ b/bindings/julia/src/database_update.jl @@ -0,0 +1,149 @@ +function update_element!(db::Database, collection::String, id::Int64, e::Element) + err = C.psr_database_update_element(db.ptr, collection, id, e.ptr) + if err != C.PSR_OK + throw(DatabaseException("Failed to update element $id in collection $collection")) + end + return nothing +end + +function update_element!(db::Database, collection::String, id::Int64; kwargs...) + e = Element() + for (k, v) in kwargs + e[String(k)] = v + end + try + update_element!(db, collection, id, e) + finally + destroy!(e) + end + return nothing +end + +# Update scalar attribute functions + +function update_scalar_integer!(db::Database, collection::String, attribute::String, id::Int64, value::Integer) + err = C.psr_database_update_scalar_integer(db.ptr, collection, attribute, id, Int64(value)) + if err != C.PSR_OK + throw(DatabaseException("Failed to update scalar integer '$collection.$attribute' for id $id")) + end + return nothing +end + +function update_scalar_double!(db::Database, collection::String, attribute::String, id::Int64, value::Real) + err = C.psr_database_update_scalar_double(db.ptr, collection, attribute, id, Float64(value)) + if err != C.PSR_OK + throw(DatabaseException("Failed to update scalar double '$collection.$attribute' for id $id")) + end + return nothing +end + +function update_scalar_string!(db::Database, collection::String, attribute::String, id::Int64, value::String) + err = C.psr_database_update_scalar_string(db.ptr, collection, attribute, id, value) + if err != C.PSR_OK + throw(DatabaseException("Failed to update scalar string '$collection.$attribute' for id $id")) + end + return nothing +end + +# Update vector attribute functions + +function update_vector_integers!( + db::Database, + collection::String, + attribute::String, + id::Int64, + values::Vector{<:Integer}, +) + int_values = Int64[Int64(v) for v in values] + err = C.psr_database_update_vector_integers( + db.ptr, + collection, + attribute, + id, + int_values, + Csize_t(length(int_values)), + ) + if err != C.PSR_OK + throw(DatabaseException("Failed to update vector integers '$collection.$attribute' for id $id")) + end + return nothing +end + +function update_vector_doubles!(db::Database, collection::String, attribute::String, id::Int64, values::Vector{<:Real}) + float_values = Float64[Float64(v) for v in values] + err = C.psr_database_update_vector_doubles( + db.ptr, + collection, + attribute, + id, + float_values, + Csize_t(length(float_values)), + ) + if err != C.PSR_OK + throw(DatabaseException("Failed to update vector doubles '$collection.$attribute' for id $id")) + end + return nothing +end + +function update_vector_strings!( + db::Database, + collection::String, + attribute::String, + id::Int64, + values::Vector{<:AbstractString}, +) + cstrings = [Base.cconvert(Cstring, s) for s in values] + ptrs = [Base.unsafe_convert(Cstring, cs) for cs in cstrings] + GC.@preserve cstrings begin + err = C.psr_database_update_vector_strings(db.ptr, collection, attribute, id, ptrs, Csize_t(length(values))) + end + if err != C.PSR_OK + throw(DatabaseException("Failed to update vector strings '$collection.$attribute' for id $id")) + end + return nothing +end + +# Update set attribute functions + +function update_set_integers!(db::Database, collection::String, attribute::String, id::Int64, values::Vector{<:Integer}) + int_values = Int64[Int64(v) for v in values] + err = C.psr_database_update_set_integers(db.ptr, collection, attribute, id, int_values, Csize_t(length(int_values))) + if err != C.PSR_OK + throw(DatabaseException("Failed to update set integers '$collection.$attribute' for id $id")) + end + return nothing +end + +function update_set_doubles!(db::Database, collection::String, attribute::String, id::Int64, values::Vector{<:Real}) + float_values = Float64[Float64(v) for v in values] + err = C.psr_database_update_set_doubles( + db.ptr, + collection, + attribute, + id, + float_values, + Csize_t(length(float_values)), + ) + if err != C.PSR_OK + throw(DatabaseException("Failed to update set doubles '$collection.$attribute' for id $id")) + end + return nothing +end + +function update_set_strings!( + db::Database, + collection::String, + attribute::String, + id::Int64, + values::Vector{<:AbstractString}, +) + cstrings = [Base.cconvert(Cstring, s) for s in values] + ptrs = [Base.unsafe_convert(Cstring, cs) for cs in cstrings] + GC.@preserve cstrings begin + err = C.psr_database_update_set_strings(db.ptr, collection, attribute, id, ptrs, Csize_t(length(values))) + end + if err != C.PSR_OK + throw(DatabaseException("Failed to update set strings '$collection.$attribute' for id $id")) + end + return nothing +end From 865bf8107222febe3eb1785d60ab28bff8b20794 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 18:45:57 -0300 Subject: [PATCH 03/32] update --- bindings/julia/src/database_create.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/julia/src/database_create.jl b/bindings/julia/src/database_create.jl index 8616bc4..cde9c24 100644 --- a/bindings/julia/src/database_create.jl +++ b/bindings/julia/src/database_create.jl @@ -30,4 +30,4 @@ function set_scalar_relation!( throw(DatabaseException("Failed to set scalar relation '$attribute' in '$collection'")) end return nothing -end \ No newline at end of file +end From ecff39a65559a548accf83a7196c0dc3a7d66e26 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 18:50:24 -0300 Subject: [PATCH 04/32] update --- bindings/julia/src/database_read.jl | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/bindings/julia/src/database_read.jl b/bindings/julia/src/database_read.jl index ed4f634..c475377 100644 --- a/bindings/julia/src/database_read.jl +++ b/bindings/julia/src/database_read.jl @@ -459,3 +459,41 @@ function get_attribute_type(db::Database, collection::String, attribute::String) return (data_structure = out_data_structure[], data_type = out_data_type[]) end + +function read(db::Database, collection::String, attribute::String) + attribute_type = get_attribute_type(db, collection, attribute) + + if attribute_type.data_structure == C.PSR_DATA_STRUCTURE_SCALAR + if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER + return read_scalar_integers(db, collection, attribute) + elseif attribute_type.data_type == C.PSR_DATA_TYPE_DOUBLE + return read_scalar_doubles(db, collection, attribute) + elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING + return read_scalar_strings(db, collection, attribute) + else + throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) + end + elseif attribute_type.data_structure == C.PSR_DATA_STRUCTURE_VECTOR + if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER + return read_vector_integers(db, collection, attribute) + elseif attribute_type.data_type == C.PSR_DATA_TYPE_DOUBLE + return read_vector_doubles(db, collection, attribute) + elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING + return read_vector_strings(db, collection, attribute) + else + throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) + end + elseif attribute_type.data_structure == C.PSR_DATA_STRUCTURE_SET + if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER + return read_set_integers(db, collection, attribute) + elseif attribute_type.data_type == C.PSR_DATA_TYPE_DOUBLE + return read_set_doubles(db, collection, attribute) + elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING + return read_set_strings(db, collection, attribute) + else + throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) + end + else + throw(DatabaseException("Unsupported data structure for '$collection.$attribute'")) + end +end \ No newline at end of file From 1620e0f0c6b370349f7aa05009251108f31fec05 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 18:51:59 -0300 Subject: [PATCH 05/32] update --- bindings/julia/test/test_read.jl | 121 +++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/bindings/julia/test/test_read.jl b/bindings/julia/test/test_read.jl index 93b69fc..34238a9 100644 --- a/bindings/julia/test/test_read.jl +++ b/bindings/julia/test/test_read.jl @@ -546,6 +546,127 @@ include("fixture.jl") PSRDatabase.close!(db) end + + # ============================================================================ + # Generic read function tests + # ============================================================================ + + @testset "Generic Read - Scalar Integer" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Config 1", integer_attribute = 42) + PSRDatabase.create_element!(db, "Configuration"; label = "Config 2", integer_attribute = 100) + + result = PSRDatabase.read(db, "Configuration", "integer_attribute") + @test result == [42, 100] + @test eltype(result) == Int64 + + PSRDatabase.close!(db) + end + + @testset "Generic Read - Scalar Double" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Config 1", float_attribute = 3.14) + PSRDatabase.create_element!(db, "Configuration"; label = "Config 2", float_attribute = 2.71) + + result = PSRDatabase.read(db, "Configuration", "float_attribute") + @test result == [3.14, 2.71] + @test eltype(result) == Float64 + + PSRDatabase.close!(db) + end + + @testset "Generic Read - Scalar String" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Config 1", string_attribute = "hello") + PSRDatabase.create_element!(db, "Configuration"; label = "Config 2", string_attribute = "world") + + result = PSRDatabase.read(db, "Configuration", "string_attribute") + @test result == ["hello", "world"] + @test eltype(result) == String + + PSRDatabase.close!(db) + end + + @testset "Generic Read - Vector Integer" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "collections.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Test Config") + PSRDatabase.create_element!(db, "Collection"; label = "Item 1", value_int = [1, 2, 3]) + PSRDatabase.create_element!(db, "Collection"; label = "Item 2", value_int = [10, 20]) + + result = PSRDatabase.read(db, "Collection", "value_int") + @test result == [[1, 2, 3], [10, 20]] + + PSRDatabase.close!(db) + end + + @testset "Generic Read - Vector Double" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "collections.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Test Config") + PSRDatabase.create_element!(db, "Collection"; label = "Item 1", value_float = [1.5, 2.5, 3.5]) + PSRDatabase.create_element!(db, "Collection"; label = "Item 2", value_float = [10.5, 20.5]) + + result = PSRDatabase.read(db, "Collection", "value_float") + @test result == [[1.5, 2.5, 3.5], [10.5, 20.5]] + + PSRDatabase.close!(db) + end + + @testset "Generic Read - Set String" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "collections.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Test Config") + PSRDatabase.create_element!(db, "Collection"; label = "Item 1", tag = ["important", "urgent"]) + PSRDatabase.create_element!(db, "Collection"; label = "Item 2", tag = ["review"]) + + result = PSRDatabase.read(db, "Collection", "tag") + @test length(result) == 2 + @test sort(result[1]) == ["important", "urgent"] + @test result[2] == ["review"] + + PSRDatabase.close!(db) + end + + @testset "Generic Read - Empty Result" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "collections.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Test Config") + + # No Collection elements, scalar returns empty array + result = PSRDatabase.read(db, "Collection", "some_integer") + @test result == Int64[] + + PSRDatabase.close!(db) + end + + @testset "Generic Read - Invalid Collection" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + @test_throws PSRDatabase.DatabaseException PSRDatabase.read(db, "NonexistentCollection", "label") + + PSRDatabase.close!(db) + end + + @testset "Generic Read - Invalid Attribute" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + @test_throws PSRDatabase.DatabaseException PSRDatabase.read(db, "Configuration", "nonexistent_attribute") + + PSRDatabase.close!(db) + end end end From bfe5e12f7ab45b6f4116dcd5fd67aec325864f2d Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 18:54:58 -0300 Subject: [PATCH 06/32] update --- bindings/julia/src/database.jl | 158 ---------------------------- bindings/julia/src/database_read.jl | 50 +++++++-- 2 files changed, 44 insertions(+), 164 deletions(-) diff --git a/bindings/julia/src/database.jl b/bindings/julia/src/database.jl index 3d069b8..5fa02e0 100644 --- a/bindings/julia/src/database.jl +++ b/bindings/julia/src/database.jl @@ -33,161 +33,3 @@ function close!(db::Database) end return nothing end - -function delete_element_by_id!(db::Database, collection::String, id::Int64) - err = C.psr_database_delete_element_by_id(db.ptr, collection, id) - if err != C.PSR_OK - throw(DatabaseException("Failed to delete element $id from '$collection'")) - end - return nothing -end - -function update_element!(db::Database, collection::String, id::Int64, e::Element) - err = C.psr_database_update_element(db.ptr, collection, id, e.ptr) - if err != C.PSR_OK - throw(DatabaseException("Failed to update element $id in collection $collection")) - end - return nothing -end - -function update_element!(db::Database, collection::String, id::Int64; kwargs...) - e = Element() - for (k, v) in kwargs - e[String(k)] = v - end - try - update_element!(db, collection, id, e) - finally - destroy!(e) - end - return nothing -end - -# Update scalar attribute functions - -function update_scalar_integer!(db::Database, collection::String, attribute::String, id::Int64, value::Integer) - err = C.psr_database_update_scalar_integer(db.ptr, collection, attribute, id, Int64(value)) - if err != C.PSR_OK - throw(DatabaseException("Failed to update scalar integer '$collection.$attribute' for id $id")) - end - return nothing -end - -function update_scalar_double!(db::Database, collection::String, attribute::String, id::Int64, value::Real) - err = C.psr_database_update_scalar_double(db.ptr, collection, attribute, id, Float64(value)) - if err != C.PSR_OK - throw(DatabaseException("Failed to update scalar double '$collection.$attribute' for id $id")) - end - return nothing -end - -function update_scalar_string!(db::Database, collection::String, attribute::String, id::Int64, value::String) - err = C.psr_database_update_scalar_string(db.ptr, collection, attribute, id, value) - if err != C.PSR_OK - throw(DatabaseException("Failed to update scalar string '$collection.$attribute' for id $id")) - end - return nothing -end - -# Update vector attribute functions - -function update_vector_integers!( - db::Database, - collection::String, - attribute::String, - id::Int64, - values::Vector{<:Integer}, -) - int_values = Int64[Int64(v) for v in values] - err = C.psr_database_update_vector_integers( - db.ptr, - collection, - attribute, - id, - int_values, - Csize_t(length(int_values)), - ) - if err != C.PSR_OK - throw(DatabaseException("Failed to update vector integers '$collection.$attribute' for id $id")) - end - return nothing -end - -function update_vector_doubles!(db::Database, collection::String, attribute::String, id::Int64, values::Vector{<:Real}) - float_values = Float64[Float64(v) for v in values] - err = C.psr_database_update_vector_doubles( - db.ptr, - collection, - attribute, - id, - float_values, - Csize_t(length(float_values)), - ) - if err != C.PSR_OK - throw(DatabaseException("Failed to update vector doubles '$collection.$attribute' for id $id")) - end - return nothing -end - -function update_vector_strings!( - db::Database, - collection::String, - attribute::String, - id::Int64, - values::Vector{<:AbstractString}, -) - cstrings = [Base.cconvert(Cstring, s) for s in values] - ptrs = [Base.unsafe_convert(Cstring, cs) for cs in cstrings] - GC.@preserve cstrings begin - err = C.psr_database_update_vector_strings(db.ptr, collection, attribute, id, ptrs, Csize_t(length(values))) - end - if err != C.PSR_OK - throw(DatabaseException("Failed to update vector strings '$collection.$attribute' for id $id")) - end - return nothing -end - -# Update set attribute functions - -function update_set_integers!(db::Database, collection::String, attribute::String, id::Int64, values::Vector{<:Integer}) - int_values = Int64[Int64(v) for v in values] - err = C.psr_database_update_set_integers(db.ptr, collection, attribute, id, int_values, Csize_t(length(int_values))) - if err != C.PSR_OK - throw(DatabaseException("Failed to update set integers '$collection.$attribute' for id $id")) - end - return nothing -end - -function update_set_doubles!(db::Database, collection::String, attribute::String, id::Int64, values::Vector{<:Real}) - float_values = Float64[Float64(v) for v in values] - err = C.psr_database_update_set_doubles( - db.ptr, - collection, - attribute, - id, - float_values, - Csize_t(length(float_values)), - ) - if err != C.PSR_OK - throw(DatabaseException("Failed to update set doubles '$collection.$attribute' for id $id")) - end - return nothing -end - -function update_set_strings!( - db::Database, - collection::String, - attribute::String, - id::Int64, - values::Vector{<:AbstractString}, -) - cstrings = [Base.cconvert(Cstring, s) for s in values] - ptrs = [Base.unsafe_convert(Cstring, cs) for cs in cstrings] - GC.@preserve cstrings begin - err = C.psr_database_update_set_strings(db.ptr, collection, attribute, id, ptrs, Csize_t(length(values))) - end - if err != C.PSR_OK - throw(DatabaseException("Failed to update set strings '$collection.$attribute' for id $id")) - end - return nothing -end diff --git a/bindings/julia/src/database_read.jl b/bindings/julia/src/database_read.jl index c475377..e357887 100644 --- a/bindings/julia/src/database_read.jl +++ b/bindings/julia/src/database_read.jl @@ -466,9 +466,9 @@ function read(db::Database, collection::String, attribute::String) if attribute_type.data_structure == C.PSR_DATA_STRUCTURE_SCALAR if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_scalar_integers(db, collection, attribute) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_DOUBLE + elseif attribute_type.data_type == C.PSR_DATA_TYPE_REAL return read_scalar_doubles(db, collection, attribute) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING + elseif attribute_type.data_type == C.PSR_DATA_TYPE_TEXT return read_scalar_strings(db, collection, attribute) else throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) @@ -476,9 +476,9 @@ function read(db::Database, collection::String, attribute::String) elseif attribute_type.data_structure == C.PSR_DATA_STRUCTURE_VECTOR if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_vector_integers(db, collection, attribute) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_DOUBLE + elseif attribute_type.data_type == C.PSR_DATA_TYPE_REAL return read_vector_doubles(db, collection, attribute) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING + elseif attribute_type.data_type == C.PSR_DATA_TYPE_TEXT return read_vector_strings(db, collection, attribute) else throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) @@ -486,9 +486,9 @@ function read(db::Database, collection::String, attribute::String) elseif attribute_type.data_structure == C.PSR_DATA_STRUCTURE_SET if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_set_integers(db, collection, attribute) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_DOUBLE + elseif attribute_type.data_type == C.PSR_DATA_TYPE_REAL return read_set_doubles(db, collection, attribute) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING + elseif attribute_type.data_type == C.PSR_DATA_TYPE_TEXT return read_set_strings(db, collection, attribute) else throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) @@ -496,4 +496,42 @@ function read(db::Database, collection::String, attribute::String) else throw(DatabaseException("Unsupported data structure for '$collection.$attribute'")) end +end + +function read_by_id(db::Database, collection::String, attribute::String, id::Int64) + attribute_type = get_attribute_type(db, collection, attribute) + + if attribute_type.data_structure == C.PSR_DATA_STRUCTURE_SCALAR + if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER + return read_scalar_integers_by_id(db, collection, attribute, id) + elseif attribute_type.data_type == C.PSR_DATA_TYPE_REAL + return read_scalar_doubles_by_id(db, collection, attribute, id) + elseif attribute_type.data_type == C.PSR_DATA_TYPE_TEXT + return read_scalar_strings_by_id(db, collection, attribute, id) + else + throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) + end + elseif attribute_type.data_structure == C.PSR_DATA_STRUCTURE_VECTOR + if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER + return read_vector_integers_by_id(db, collection, attribute, id) + elseif attribute_type.data_type == C.PSR_DATA_TYPE_REAL + return read_vector_doubles_by_id(db, collection, attribute, id) + elseif attribute_type.data_type == C.PSR_DATA_TYPE_TEXT + return read_vector_strings_by_id(db, collection, attribute, id) + else + throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) + end + elseif attribute_type.data_structure == C.PSR_DATA_STRUCTURE_SET + if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER + return read_set_integers_by_id(db, collection, attribute, id) + elseif attribute_type.data_type == C.PSR_DATA_TYPE_REAL + return read_set_doubles_by_id(db, collection, attribute, id) + elseif attribute_type.data_type == C.PSR_DATA_TYPE_TEXT + return read_set_strings_by_id(db, collection, attribute, id) + else + throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) + end + else + throw(DatabaseException("Unsupported data structure for '$collection.$attribute'")) + end end \ No newline at end of file From a41a3a1d9e4da872dc6d5ad4ed9a8e5b436e143b Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 18:55:46 -0300 Subject: [PATCH 07/32] update --- bindings/dart/lib/src/database.dart | 4 ++-- bindings/dart/lib/src/ffi/bindings.dart | 4 ++-- bindings/julia/src/PSRDatabase.jl | 6 +++--- bindings/julia/src/c_api.jl | 4 ++-- bindings/julia/src/database_read.jl | 24 ++++++++++++------------ bindings/julia/test/test_read.jl | 8 ++++---- include/psr/c/database.h | 2 +- src/c_api_database.cpp | 4 ++-- tests/test_c_api_database_read.cpp | 8 ++++---- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/bindings/dart/lib/src/database.dart b/bindings/dart/lib/src/database.dart index 632c6f8..4178632 100644 --- a/bindings/dart/lib/src/database.dart +++ b/bindings/dart/lib/src/database.dart @@ -897,8 +897,8 @@ class Database { final dataType = switch (outDataType.value) { psr_data_type_t.PSR_DATA_TYPE_INTEGER => 'integer', - psr_data_type_t.PSR_DATA_TYPE_REAL => 'real', - psr_data_type_t.PSR_DATA_TYPE_TEXT => 'text', + psr_data_type_t.PSR_DATA_TYPE_FLOAT => 'real', + psr_data_type_t.PSR_DATA_TYPE_STRING => 'text', _ => 'unknown', }; diff --git a/bindings/dart/lib/src/ffi/bindings.dart b/bindings/dart/lib/src/ffi/bindings.dart index 4dd3de3..987014c 100644 --- a/bindings/dart/lib/src/ffi/bindings.dart +++ b/bindings/dart/lib/src/ffi/bindings.dart @@ -1502,8 +1502,8 @@ abstract class psr_data_structure_t { abstract class psr_data_type_t { static const int PSR_DATA_TYPE_INTEGER = 0; - static const int PSR_DATA_TYPE_REAL = 1; - static const int PSR_DATA_TYPE_TEXT = 2; + static const int PSR_DATA_TYPE_FLOAT = 1; + static const int PSR_DATA_TYPE_STRING = 2; } final class psr_database extends ffi.Opaque {} diff --git a/bindings/julia/src/PSRDatabase.jl b/bindings/julia/src/PSRDatabase.jl index 5cdeb30..ef63eb4 100644 --- a/bindings/julia/src/PSRDatabase.jl +++ b/bindings/julia/src/PSRDatabase.jl @@ -15,14 +15,14 @@ include("lua_runner.jl") export Element, Database, LuaRunner, DatabaseException export get_attribute_type export PSR_DATA_STRUCTURE_SCALAR, PSR_DATA_STRUCTURE_VECTOR, PSR_DATA_STRUCTURE_SET -export PSR_DATA_TYPE_INTEGER, PSR_DATA_TYPE_REAL, PSR_DATA_TYPE_TEXT +export PSR_DATA_TYPE_INTEGER, PSR_DATA_TYPE_FLOAT, PSR_DATA_TYPE_STRING # Re-export enums from C module const PSR_DATA_STRUCTURE_SCALAR = C.PSR_DATA_STRUCTURE_SCALAR const PSR_DATA_STRUCTURE_VECTOR = C.PSR_DATA_STRUCTURE_VECTOR const PSR_DATA_STRUCTURE_SET = C.PSR_DATA_STRUCTURE_SET const PSR_DATA_TYPE_INTEGER = C.PSR_DATA_TYPE_INTEGER -const PSR_DATA_TYPE_REAL = C.PSR_DATA_TYPE_REAL -const PSR_DATA_TYPE_TEXT = C.PSR_DATA_TYPE_TEXT +const PSR_DATA_TYPE_FLOAT = C.PSR_DATA_TYPE_FLOAT +const PSR_DATA_TYPE_STRING = C.PSR_DATA_TYPE_STRING end diff --git a/bindings/julia/src/c_api.jl b/bindings/julia/src/c_api.jl index e403c7f..ffe6f47 100644 --- a/bindings/julia/src/c_api.jl +++ b/bindings/julia/src/c_api.jl @@ -66,8 +66,8 @@ end @cenum psr_data_type_t::UInt32 begin PSR_DATA_TYPE_INTEGER = 0 - PSR_DATA_TYPE_REAL = 1 - PSR_DATA_TYPE_TEXT = 2 + PSR_DATA_TYPE_FLOAT = 1 + PSR_DATA_TYPE_STRING = 2 end function psr_database_options_default() diff --git a/bindings/julia/src/database_read.jl b/bindings/julia/src/database_read.jl index e357887..2edc9ca 100644 --- a/bindings/julia/src/database_read.jl +++ b/bindings/julia/src/database_read.jl @@ -466,9 +466,9 @@ function read(db::Database, collection::String, attribute::String) if attribute_type.data_structure == C.PSR_DATA_STRUCTURE_SCALAR if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_scalar_integers(db, collection, attribute) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_REAL + elseif attribute_type.data_type == C.PSR_DATA_TYPE_FLOAT return read_scalar_doubles(db, collection, attribute) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_TEXT + elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_scalar_strings(db, collection, attribute) else throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) @@ -476,9 +476,9 @@ function read(db::Database, collection::String, attribute::String) elseif attribute_type.data_structure == C.PSR_DATA_STRUCTURE_VECTOR if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_vector_integers(db, collection, attribute) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_REAL + elseif attribute_type.data_type == C.PSR_DATA_TYPE_FLOAT return read_vector_doubles(db, collection, attribute) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_TEXT + elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_vector_strings(db, collection, attribute) else throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) @@ -486,9 +486,9 @@ function read(db::Database, collection::String, attribute::String) elseif attribute_type.data_structure == C.PSR_DATA_STRUCTURE_SET if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_set_integers(db, collection, attribute) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_REAL + elseif attribute_type.data_type == C.PSR_DATA_TYPE_FLOAT return read_set_doubles(db, collection, attribute) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_TEXT + elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_set_strings(db, collection, attribute) else throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) @@ -504,9 +504,9 @@ function read_by_id(db::Database, collection::String, attribute::String, id::Int if attribute_type.data_structure == C.PSR_DATA_STRUCTURE_SCALAR if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_scalar_integers_by_id(db, collection, attribute, id) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_REAL + elseif attribute_type.data_type == C.PSR_DATA_TYPE_FLOAT return read_scalar_doubles_by_id(db, collection, attribute, id) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_TEXT + elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_scalar_strings_by_id(db, collection, attribute, id) else throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) @@ -514,9 +514,9 @@ function read_by_id(db::Database, collection::String, attribute::String, id::Int elseif attribute_type.data_structure == C.PSR_DATA_STRUCTURE_VECTOR if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_vector_integers_by_id(db, collection, attribute, id) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_REAL + elseif attribute_type.data_type == C.PSR_DATA_TYPE_FLOAT return read_vector_doubles_by_id(db, collection, attribute, id) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_TEXT + elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_vector_strings_by_id(db, collection, attribute, id) else throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) @@ -524,9 +524,9 @@ function read_by_id(db::Database, collection::String, attribute::String, id::Int elseif attribute_type.data_structure == C.PSR_DATA_STRUCTURE_SET if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_set_integers_by_id(db, collection, attribute, id) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_REAL + elseif attribute_type.data_type == C.PSR_DATA_TYPE_FLOAT return read_set_doubles_by_id(db, collection, attribute, id) - elseif attribute_type.data_type == C.PSR_DATA_TYPE_TEXT + elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_set_strings_by_id(db, collection, attribute, id) else throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) diff --git a/bindings/julia/test/test_read.jl b/bindings/julia/test/test_read.jl index 34238a9..a40c8f8 100644 --- a/bindings/julia/test/test_read.jl +++ b/bindings/julia/test/test_read.jl @@ -380,7 +380,7 @@ include("fixture.jl") result = PSRDatabase.get_attribute_type(db, "Configuration", "float_attribute") @test result.data_structure == PSRDatabase.PSR_DATA_STRUCTURE_SCALAR - @test result.data_type == PSRDatabase.PSR_DATA_TYPE_REAL + @test result.data_type == PSRDatabase.PSR_DATA_TYPE_FLOAT PSRDatabase.close!(db) end @@ -391,7 +391,7 @@ include("fixture.jl") result = PSRDatabase.get_attribute_type(db, "Configuration", "string_attribute") @test result.data_structure == PSRDatabase.PSR_DATA_STRUCTURE_SCALAR - @test result.data_type == PSRDatabase.PSR_DATA_TYPE_TEXT + @test result.data_type == PSRDatabase.PSR_DATA_TYPE_STRING PSRDatabase.close!(db) end @@ -413,7 +413,7 @@ include("fixture.jl") result = PSRDatabase.get_attribute_type(db, "Collection", "value_float") @test result.data_structure == PSRDatabase.PSR_DATA_STRUCTURE_VECTOR - @test result.data_type == PSRDatabase.PSR_DATA_TYPE_REAL + @test result.data_type == PSRDatabase.PSR_DATA_TYPE_FLOAT PSRDatabase.close!(db) end @@ -424,7 +424,7 @@ include("fixture.jl") result = PSRDatabase.get_attribute_type(db, "Collection", "tag") @test result.data_structure == PSRDatabase.PSR_DATA_STRUCTURE_SET - @test result.data_type == PSRDatabase.PSR_DATA_TYPE_TEXT + @test result.data_type == PSRDatabase.PSR_DATA_TYPE_STRING PSRDatabase.close!(db) end diff --git a/include/psr/c/database.h b/include/psr/c/database.h index c9a4ed8..d0f4ac2 100644 --- a/include/psr/c/database.h +++ b/include/psr/c/database.h @@ -30,7 +30,7 @@ typedef enum { } psr_data_structure_t; // Attribute data types -typedef enum { PSR_DATA_TYPE_INTEGER = 0, PSR_DATA_TYPE_REAL = 1, PSR_DATA_TYPE_TEXT = 2 } psr_data_type_t; +typedef enum { PSR_DATA_TYPE_INTEGER = 0, PSR_DATA_TYPE_FLOAT = 1, PSR_DATA_TYPE_STRING = 2 } psr_data_type_t; // Returns default options PSR_C_API psr_database_options_t psr_database_options_default(void); diff --git a/src/c_api_database.cpp b/src/c_api_database.cpp index f16ec0f..2ca27da 100644 --- a/src/c_api_database.cpp +++ b/src/c_api_database.cpp @@ -909,10 +909,10 @@ PSR_C_API psr_error_t psr_database_get_attribute_type(psr_database_t* db, *out_data_type = PSR_DATA_TYPE_INTEGER; break; case psr::DataType::Real: - *out_data_type = PSR_DATA_TYPE_REAL; + *out_data_type = PSR_DATA_TYPE_FLOAT; break; case psr::DataType::Text: - *out_data_type = PSR_DATA_TYPE_TEXT; + *out_data_type = PSR_DATA_TYPE_STRING; break; } diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index ba0d7a2..3b02eee 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -832,7 +832,7 @@ TEST(DatabaseCApi, GetAttributeTypeScalarReal) { EXPECT_EQ(err, PSR_OK); EXPECT_EQ(data_structure, PSR_DATA_STRUCTURE_SCALAR); - EXPECT_EQ(data_type, PSR_DATA_TYPE_REAL); + EXPECT_EQ(data_type, PSR_DATA_TYPE_FLOAT); psr_database_close(db); } @@ -849,7 +849,7 @@ TEST(DatabaseCApi, GetAttributeTypeScalarText) { EXPECT_EQ(err, PSR_OK); EXPECT_EQ(data_structure, PSR_DATA_STRUCTURE_SCALAR); - EXPECT_EQ(data_type, PSR_DATA_TYPE_TEXT); + EXPECT_EQ(data_type, PSR_DATA_TYPE_STRING); psr_database_close(db); } @@ -883,7 +883,7 @@ TEST(DatabaseCApi, GetAttributeTypeVectorReal) { EXPECT_EQ(err, PSR_OK); EXPECT_EQ(data_structure, PSR_DATA_STRUCTURE_VECTOR); - EXPECT_EQ(data_type, PSR_DATA_TYPE_REAL); + EXPECT_EQ(data_type, PSR_DATA_TYPE_FLOAT); psr_database_close(db); } @@ -900,7 +900,7 @@ TEST(DatabaseCApi, GetAttributeTypeSetText) { EXPECT_EQ(err, PSR_OK); EXPECT_EQ(data_structure, PSR_DATA_STRUCTURE_SET); - EXPECT_EQ(data_type, PSR_DATA_TYPE_TEXT); + EXPECT_EQ(data_type, PSR_DATA_TYPE_STRING); psr_database_close(db); } From 33ee470b252e16217942140ccb1acd64ad121599 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 18:57:15 -0300 Subject: [PATCH 08/32] update --- CLAUDE.md | 10 ++-- bindings/dart/lib/src/database.dart | 44 +++++++------- bindings/dart/lib/src/element.dart | 4 +- bindings/dart/lib/src/ffi/bindings.dart | 80 ++++++++++++------------- bindings/dart/test/create_test.dart | 2 +- bindings/dart/test/lua_runner_test.dart | 8 +-- bindings/dart/test/read_test.dart | 30 +++++----- bindings/dart/test/update_test.dart | 14 ++--- bindings/julia/src/c_api.jl | 32 +++++----- bindings/julia/src/database_read.jl | 46 +++++++------- bindings/julia/src/database_update.jl | 12 ++-- bindings/julia/test/test_create.jl | 2 +- bindings/julia/test/test_lua_runner.jl | 6 +- bindings/julia/test/test_read.jl | 28 ++++----- bindings/julia/test/test_update.jl | 24 ++++---- include/psr/c/database.h | 16 ++--- include/psr/database.h | 16 ++--- src/c_api_database.cpp | 32 +++++----- src/database.cpp | 16 ++--- src/lua_runner.cpp | 40 ++++++------- tests/test_c_api_database_read.cpp | 70 +++++++++++----------- tests/test_c_api_database_update.cpp | 26 ++++---- tests/test_database_create.cpp | 6 +- tests/test_database_errors.cpp | 24 ++++---- tests/test_database_read.cpp | 26 ++++---- tests/test_database_update.cpp | 10 ++-- tests/test_lua_runner.cpp | 32 +++++----- tests/test_row_result.cpp | 2 +- tests/test_schema_validator.cpp | 2 +- 29 files changed, 330 insertions(+), 330 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index d8776a9..06d1c8a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -78,9 +78,9 @@ bindings/dart/test/test.bat ### Database Class - Factory methods: `from_schema()`, `from_migrations()` - CRUD: `create_element(collection, element)` -- Scalar readers: `read_scalar_integers/doubles/strings(collection, attribute)` -- Vector readers: `read_vector_integers/doubles/strings(collection, attribute)` -- Set readers: `read_set_integers/doubles/strings(collection, attribute)` +- Scalar readers: `read_scalar_integers/floats/strings(collection, attribute)` +- Vector readers: `read_vector_integers/floats/strings(collection, attribute)` +- Set readers: `read_set_integers/floats/strings(collection, attribute)` - Relations: `set_scalar_relation()`, `read_scalar_relation()` ### Element Class @@ -101,8 +101,8 @@ lua.run(R"( Available Lua methods: - `db:create_element(collection, table)` -- `db:read_scalar_strings/integers/doubles(collection, attribute)` -- `db:read_vector_strings/integers/doubles(collection, attribute)` +- `db:read_scalar_strings/integers/floats(collection, attribute)` +- `db:read_vector_strings/integers/floats(collection, attribute)` ## Bindings diff --git a/bindings/dart/lib/src/database.dart b/bindings/dart/lib/src/database.dart index 4178632..aee5d27 100644 --- a/bindings/dart/lib/src/database.dart +++ b/bindings/dart/lib/src/database.dart @@ -187,7 +187,7 @@ class Database { } /// Reads all double values for a scalar attribute from a collection. - List readScalarDoubles(String collection, String attribute) { + List readScalarFloats(String collection, String attribute) { _ensureNotClosed(); final arena = Arena(); @@ -195,7 +195,7 @@ class Database { final outValues = arena>(); final outCount = arena(); - final err = bindings.psr_database_read_scalar_doubles( + final err = bindings.psr_database_read_scalar_floats( _ptr, collection.toNativeUtf8(allocator: arena).cast(), attribute.toNativeUtf8(allocator: arena).cast(), @@ -204,7 +204,7 @@ class Database { ); if (err != psr_error_t.PSR_OK) { - throw DatabaseException.fromError(err, "Failed to read scalar doubles from '$collection.$attribute'"); + throw DatabaseException.fromError(err, "Failed to read scalar floats from '$collection.$attribute'"); } final count = outCount.value; @@ -299,7 +299,7 @@ class Database { } /// Reads all double vectors for a vector attribute from a collection. - List> readVectorDoubles(String collection, String attribute) { + List> readVectorFloats(String collection, String attribute) { _ensureNotClosed(); final arena = Arena(); @@ -308,7 +308,7 @@ class Database { final outSizes = arena>(); final outCount = arena(); - final err = bindings.psr_database_read_vector_doubles( + final err = bindings.psr_database_read_vector_floats( _ptr, collection.toNativeUtf8(allocator: arena).cast(), attribute.toNativeUtf8(allocator: arena).cast(), @@ -318,7 +318,7 @@ class Database { ); if (err != psr_error_t.PSR_OK) { - throw DatabaseException.fromError(err, "Failed to read vector doubles from '$collection.$attribute'"); + throw DatabaseException.fromError(err, "Failed to read vector floats from '$collection.$attribute'"); } final count = outCount.value; @@ -431,7 +431,7 @@ class Database { } /// Reads all double sets for a set attribute from a collection. - List> readSetDoubles(String collection, String attribute) { + List> readSetFloats(String collection, String attribute) { _ensureNotClosed(); final arena = Arena(); @@ -440,7 +440,7 @@ class Database { final outSizes = arena>(); final outCount = arena(); - final err = bindings.psr_database_read_set_doubles( + final err = bindings.psr_database_read_set_floats( _ptr, collection.toNativeUtf8(allocator: arena).cast(), attribute.toNativeUtf8(allocator: arena).cast(), @@ -450,7 +450,7 @@ class Database { ); if (err != psr_error_t.PSR_OK) { - throw DatabaseException.fromError(err, "Failed to read set doubles from '$collection.$attribute'"); + throw DatabaseException.fromError(err, "Failed to read set floats from '$collection.$attribute'"); } final count = outCount.value; @@ -562,7 +562,7 @@ class Database { final outValue = arena(); final outHasValue = arena(); - final err = bindings.psr_database_read_scalar_doubles_by_id( + final err = bindings.psr_database_read_scalar_floats_by_id( _ptr, collection.toNativeUtf8(allocator: arena).cast(), attribute.toNativeUtf8(allocator: arena).cast(), @@ -656,7 +656,7 @@ class Database { } /// Reads double vector for a vector attribute by element ID. - List readVectorDoublesById(String collection, String attribute, int id) { + List readVectorFloatsById(String collection, String attribute, int id) { _ensureNotClosed(); final arena = Arena(); @@ -664,7 +664,7 @@ class Database { final outValues = arena>(); final outCount = arena(); - final err = bindings.psr_database_read_vector_doubles_by_id( + final err = bindings.psr_database_read_vector_floats_by_id( _ptr, collection.toNativeUtf8(allocator: arena).cast(), attribute.toNativeUtf8(allocator: arena).cast(), @@ -674,7 +674,7 @@ class Database { ); if (err != psr_error_t.PSR_OK) { - throw DatabaseException.fromError(err, "Failed to read vector doubles by id from '$collection.$attribute'"); + throw DatabaseException.fromError(err, "Failed to read vector floats by id from '$collection.$attribute'"); } final count = outCount.value; @@ -763,7 +763,7 @@ class Database { } /// Reads double set for a set attribute by element ID. - List readSetDoublesById(String collection, String attribute, int id) { + List readSetFloatsById(String collection, String attribute, int id) { _ensureNotClosed(); final arena = Arena(); @@ -771,7 +771,7 @@ class Database { final outValues = arena>(); final outCount = arena(); - final err = bindings.psr_database_read_set_doubles_by_id( + final err = bindings.psr_database_read_set_floats_by_id( _ptr, collection.toNativeUtf8(allocator: arena).cast(), attribute.toNativeUtf8(allocator: arena).cast(), @@ -781,7 +781,7 @@ class Database { ); if (err != psr_error_t.PSR_OK) { - throw DatabaseException.fromError(err, "Failed to read set doubles by id from '$collection.$attribute'"); + throw DatabaseException.fromError(err, "Failed to read set floats by id from '$collection.$attribute'"); } final count = outCount.value; @@ -1063,7 +1063,7 @@ class Database { } /// Updates a double vector attribute by element ID (replaces entire vector). - void updateVectorDoubles(String collection, String attribute, int id, List values) { + void updateVectorFloats(String collection, String attribute, int id, List values) { _ensureNotClosed(); final arena = Arena(); @@ -1073,7 +1073,7 @@ class Database { nativeValues[i] = values[i]; } - final err = bindings.psr_database_update_vector_doubles( + final err = bindings.psr_database_update_vector_floats( _ptr, collection.toNativeUtf8(allocator: arena).cast(), attribute.toNativeUtf8(allocator: arena).cast(), @@ -1083,7 +1083,7 @@ class Database { ); if (err != psr_error_t.PSR_OK) { - throw DatabaseException.fromError(err, "Failed to update vector doubles '$collection.$attribute' for id $id"); + throw DatabaseException.fromError(err, "Failed to update vector floats '$collection.$attribute' for id $id"); } } finally { arena.releaseAll(); @@ -1149,7 +1149,7 @@ class Database { } /// Updates a double set attribute by element ID (replaces entire set). - void updateSetDoubles(String collection, String attribute, int id, List values) { + void updateSetFloats(String collection, String attribute, int id, List values) { _ensureNotClosed(); final arena = Arena(); @@ -1159,7 +1159,7 @@ class Database { nativeValues[i] = values[i]; } - final err = bindings.psr_database_update_set_doubles( + final err = bindings.psr_database_update_set_floats( _ptr, collection.toNativeUtf8(allocator: arena).cast(), attribute.toNativeUtf8(allocator: arena).cast(), @@ -1169,7 +1169,7 @@ class Database { ); if (err != psr_error_t.PSR_OK) { - throw DatabaseException.fromError(err, "Failed to update set doubles '$collection.$attribute' for id $id"); + throw DatabaseException.fromError(err, "Failed to update set floats '$collection.$attribute' for id $id"); } } finally { arena.releaseAll(); diff --git a/bindings/dart/lib/src/element.dart b/bindings/dart/lib/src/element.dart index c6f913a..84583aa 100644 --- a/bindings/dart/lib/src/element.dart +++ b/bindings/dart/lib/src/element.dart @@ -41,7 +41,7 @@ class Element { /// - `double` - 64-bit floating point /// - `String` - UTF-8 string /// - `List` - array of integers - /// - `List` - array of doubles + /// - `List` - array of floats /// - `List` - array of strings void set(String name, Object? value) { _ensureNotDisposed(); @@ -174,7 +174,7 @@ class Element { } } - /// Sets an array of doubles. + /// Sets an array of floats. void setArrayDouble(String name, List values) { _ensureNotDisposed(); final namePtr = name.toNativeUtf8(); diff --git a/bindings/dart/lib/src/ffi/bindings.dart b/bindings/dart/lib/src/ffi/bindings.dart index 987014c..10afc39 100644 --- a/bindings/dart/lib/src/ffi/bindings.dart +++ b/bindings/dart/lib/src/ffi/bindings.dart @@ -289,14 +289,14 @@ class PsrDatabaseBindings { int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Pointer>, ffi.Pointer)>(); - int psr_database_read_scalar_doubles( + int psr_database_read_scalar_floats( ffi.Pointer db, ffi.Pointer collection, ffi.Pointer attribute, ffi.Pointer> out_values, ffi.Pointer out_count, ) { - return _psr_database_read_scalar_doubles( + return _psr_database_read_scalar_floats( db, collection, attribute, @@ -305,11 +305,11 @@ class PsrDatabaseBindings { ); } - late final _psr_database_read_scalar_doublesPtr = _lookup< + late final _psr_database_read_scalar_floatsPtr = _lookup< ffi.NativeFunction< ffi.Int32 Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, - ffi.Pointer>, ffi.Pointer)>>('psr_database_read_scalar_doubles'); - late final _psr_database_read_scalar_doubles = _psr_database_read_scalar_doublesPtr.asFunction< + ffi.Pointer>, ffi.Pointer)>>('psr_database_read_scalar_floats'); + late final _psr_database_read_scalar_floats = _psr_database_read_scalar_floatsPtr.asFunction< int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Pointer>, ffi.Pointer)>(); @@ -377,7 +377,7 @@ class PsrDatabaseBindings { ffi.Pointer>, ffi.Pointer)>(); - int psr_database_read_vector_doubles( + int psr_database_read_vector_floats( ffi.Pointer db, ffi.Pointer collection, ffi.Pointer attribute, @@ -385,7 +385,7 @@ class PsrDatabaseBindings { ffi.Pointer> out_sizes, ffi.Pointer out_count, ) { - return _psr_database_read_vector_doubles( + return _psr_database_read_vector_floats( db, collection, attribute, @@ -395,7 +395,7 @@ class PsrDatabaseBindings { ); } - late final _psr_database_read_vector_doublesPtr = _lookup< + late final _psr_database_read_vector_floatsPtr = _lookup< ffi.NativeFunction< ffi.Int32 Function( ffi.Pointer, @@ -403,8 +403,8 @@ class PsrDatabaseBindings { ffi.Pointer, ffi.Pointer>>, ffi.Pointer>, - ffi.Pointer)>>('psr_database_read_vector_doubles'); - late final _psr_database_read_vector_doubles = _psr_database_read_vector_doublesPtr.asFunction< + ffi.Pointer)>>('psr_database_read_vector_floats'); + late final _psr_database_read_vector_floats = _psr_database_read_vector_floatsPtr.asFunction< int Function( ffi.Pointer, ffi.Pointer, @@ -485,7 +485,7 @@ class PsrDatabaseBindings { ffi.Pointer>, ffi.Pointer)>(); - int psr_database_read_set_doubles( + int psr_database_read_set_floats( ffi.Pointer db, ffi.Pointer collection, ffi.Pointer attribute, @@ -493,7 +493,7 @@ class PsrDatabaseBindings { ffi.Pointer> out_sizes, ffi.Pointer out_count, ) { - return _psr_database_read_set_doubles( + return _psr_database_read_set_floats( db, collection, attribute, @@ -503,7 +503,7 @@ class PsrDatabaseBindings { ); } - late final _psr_database_read_set_doublesPtr = _lookup< + late final _psr_database_read_set_floatsPtr = _lookup< ffi.NativeFunction< ffi.Int32 Function( ffi.Pointer, @@ -511,8 +511,8 @@ class PsrDatabaseBindings { ffi.Pointer, ffi.Pointer>>, ffi.Pointer>, - ffi.Pointer)>>('psr_database_read_set_doubles'); - late final _psr_database_read_set_doubles = _psr_database_read_set_doublesPtr.asFunction< + ffi.Pointer)>>('psr_database_read_set_floats'); + late final _psr_database_read_set_floats = _psr_database_read_set_floatsPtr.asFunction< int Function( ffi.Pointer, ffi.Pointer, @@ -583,7 +583,7 @@ class PsrDatabaseBindings { int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, ffi.Pointer, ffi.Pointer)>(); - int psr_database_read_scalar_doubles_by_id( + int psr_database_read_scalar_floats_by_id( ffi.Pointer db, ffi.Pointer collection, ffi.Pointer attribute, @@ -591,7 +591,7 @@ class PsrDatabaseBindings { ffi.Pointer out_value, ffi.Pointer out_has_value, ) { - return _psr_database_read_scalar_doubles_by_id( + return _psr_database_read_scalar_floats_by_id( db, collection, attribute, @@ -601,11 +601,11 @@ class PsrDatabaseBindings { ); } - late final _psr_database_read_scalar_doubles_by_idPtr = _lookup< + late final _psr_database_read_scalar_floats_by_idPtr = _lookup< ffi.NativeFunction< ffi.Int32 Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Int64, - ffi.Pointer, ffi.Pointer)>>('psr_database_read_scalar_doubles_by_id'); - late final _psr_database_read_scalar_doubles_by_id = _psr_database_read_scalar_doubles_by_idPtr.asFunction< + ffi.Pointer, ffi.Pointer)>>('psr_database_read_scalar_floats_by_id'); + late final _psr_database_read_scalar_floats_by_id = _psr_database_read_scalar_floats_by_idPtr.asFunction< int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, ffi.Pointer, ffi.Pointer)>(); @@ -661,7 +661,7 @@ class PsrDatabaseBindings { int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, ffi.Pointer>, ffi.Pointer)>(); - int psr_database_read_vector_doubles_by_id( + int psr_database_read_vector_floats_by_id( ffi.Pointer db, ffi.Pointer collection, ffi.Pointer attribute, @@ -669,7 +669,7 @@ class PsrDatabaseBindings { ffi.Pointer> out_values, ffi.Pointer out_count, ) { - return _psr_database_read_vector_doubles_by_id( + return _psr_database_read_vector_floats_by_id( db, collection, attribute, @@ -679,11 +679,11 @@ class PsrDatabaseBindings { ); } - late final _psr_database_read_vector_doubles_by_idPtr = _lookup< + late final _psr_database_read_vector_floats_by_idPtr = _lookup< ffi.NativeFunction< ffi.Int32 Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Int64, - ffi.Pointer>, ffi.Pointer)>>('psr_database_read_vector_doubles_by_id'); - late final _psr_database_read_vector_doubles_by_id = _psr_database_read_vector_doubles_by_idPtr.asFunction< + ffi.Pointer>, ffi.Pointer)>>('psr_database_read_vector_floats_by_id'); + late final _psr_database_read_vector_floats_by_id = _psr_database_read_vector_floats_by_idPtr.asFunction< int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, ffi.Pointer>, ffi.Pointer)>(); @@ -744,7 +744,7 @@ class PsrDatabaseBindings { int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, ffi.Pointer>, ffi.Pointer)>(); - int psr_database_read_set_doubles_by_id( + int psr_database_read_set_floats_by_id( ffi.Pointer db, ffi.Pointer collection, ffi.Pointer attribute, @@ -752,7 +752,7 @@ class PsrDatabaseBindings { ffi.Pointer> out_values, ffi.Pointer out_count, ) { - return _psr_database_read_set_doubles_by_id( + return _psr_database_read_set_floats_by_id( db, collection, attribute, @@ -762,11 +762,11 @@ class PsrDatabaseBindings { ); } - late final _psr_database_read_set_doubles_by_idPtr = _lookup< + late final _psr_database_read_set_floats_by_idPtr = _lookup< ffi.NativeFunction< ffi.Int32 Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Int64, - ffi.Pointer>, ffi.Pointer)>>('psr_database_read_set_doubles_by_id'); - late final _psr_database_read_set_doubles_by_id = _psr_database_read_set_doubles_by_idPtr.asFunction< + ffi.Pointer>, ffi.Pointer)>>('psr_database_read_set_floats_by_id'); + late final _psr_database_read_set_floats_by_id = _psr_database_read_set_floats_by_idPtr.asFunction< int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, ffi.Pointer>, ffi.Pointer)>(); @@ -943,7 +943,7 @@ class PsrDatabaseBindings { int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, ffi.Pointer, int)>(); - int psr_database_update_vector_doubles( + int psr_database_update_vector_floats( ffi.Pointer db, ffi.Pointer collection, ffi.Pointer attribute, @@ -951,7 +951,7 @@ class PsrDatabaseBindings { ffi.Pointer values, int count, ) { - return _psr_database_update_vector_doubles( + return _psr_database_update_vector_floats( db, collection, attribute, @@ -961,11 +961,11 @@ class PsrDatabaseBindings { ); } - late final _psr_database_update_vector_doublesPtr = _lookup< + late final _psr_database_update_vector_floatsPtr = _lookup< ffi.NativeFunction< ffi.Int32 Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Int64, - ffi.Pointer, ffi.Size)>>('psr_database_update_vector_doubles'); - late final _psr_database_update_vector_doubles = _psr_database_update_vector_doublesPtr.asFunction< + ffi.Pointer, ffi.Size)>>('psr_database_update_vector_floats'); + late final _psr_database_update_vector_floats = _psr_database_update_vector_floatsPtr.asFunction< int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, ffi.Pointer, int)>(); @@ -1021,7 +1021,7 @@ class PsrDatabaseBindings { int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, ffi.Pointer, int)>(); - int psr_database_update_set_doubles( + int psr_database_update_set_floats( ffi.Pointer db, ffi.Pointer collection, ffi.Pointer attribute, @@ -1029,7 +1029,7 @@ class PsrDatabaseBindings { ffi.Pointer values, int count, ) { - return _psr_database_update_set_doubles( + return _psr_database_update_set_floats( db, collection, attribute, @@ -1039,11 +1039,11 @@ class PsrDatabaseBindings { ); } - late final _psr_database_update_set_doublesPtr = _lookup< + late final _psr_database_update_set_floatsPtr = _lookup< ffi.NativeFunction< ffi.Int32 Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Int64, - ffi.Pointer, ffi.Size)>>('psr_database_update_set_doubles'); - late final _psr_database_update_set_doubles = _psr_database_update_set_doublesPtr.asFunction< + ffi.Pointer, ffi.Size)>>('psr_database_update_set_floats'); + late final _psr_database_update_set_floats = _psr_database_update_set_floatsPtr.asFunction< int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, ffi.Pointer, int)>(); diff --git a/bindings/dart/test/create_test.dart b/bindings/dart/test/create_test.dart index 1a4d830..e167833 100644 --- a/bindings/dart/test/create_test.dart +++ b/bindings/dart/test/create_test.dart @@ -379,7 +379,7 @@ void main() { }); expect(id, greaterThan(0)); - final result = db.readVectorDoublesById('Collection', 'value_float', 1); + final result = db.readVectorFloatsById('Collection', 'value_float', 1); expect(result.length, equals(3)); expect(result, equals([1.1, 2.2, 3.3])); } finally { diff --git a/bindings/dart/test/lua_runner_test.dart b/bindings/dart/test/lua_runner_test.dart index 09cd8e8..f204657 100644 --- a/bindings/dart/test/lua_runner_test.dart +++ b/bindings/dart/test/lua_runner_test.dart @@ -235,8 +235,8 @@ void main() { }); }); - group('LuaRunner Read Doubles', () { - test('reads scalar doubles in Lua script', () { + group('LuaRunner Read Floats', () { + test('reads scalar floats in Lua script', () { final db = Database.fromSchema( ':memory:', path.join(testsPath, 'schemas', 'valid', 'collections.sql'), @@ -249,8 +249,8 @@ void main() { final lua = LuaRunner(db); try { lua.run(''' - local floats = db:read_scalar_doubles("Collection", "some_float") - assert(#floats == 2, "Expected 2 doubles") + local floats = db:read_scalar_floats("Collection", "some_float") + assert(#floats == 2, "Expected 2 floats") assert(floats[1] == 1.5, "First double mismatch") assert(floats[2] == 2.5, "Second double mismatch") '''); diff --git a/bindings/dart/test/read_test.dart b/bindings/dart/test/read_test.dart index 8ce6d93..c12f4b2 100644 --- a/bindings/dart/test/read_test.dart +++ b/bindings/dart/test/read_test.dart @@ -64,7 +64,7 @@ void main() { } }); - test('reads doubles from Configuration', () { + test('reads floats from Configuration', () { final db = Database.fromSchema( ':memory:', path.join(testsPath, 'schemas', 'valid', 'basic.sql'), @@ -80,7 +80,7 @@ void main() { }); expect( - db.readScalarDoubles('Configuration', 'float_attribute'), + db.readScalarFloats('Configuration', 'float_attribute'), equals([3.14, 2.71]), ); } finally { @@ -117,7 +117,7 @@ void main() { equals([10, 20]), ); expect( - db.readScalarDoubles('Collection', 'some_float'), + db.readScalarFloats('Collection', 'some_float'), equals([1.5, 2.5]), ); } finally { @@ -137,7 +137,7 @@ void main() { expect(db.readScalarStrings('Collection', 'label'), isEmpty); expect(db.readScalarIntegers('Collection', 'some_integer'), isEmpty); - expect(db.readScalarDoubles('Collection', 'some_float'), isEmpty); + expect(db.readScalarFloats('Collection', 'some_float'), isEmpty); } finally { db.close(); } @@ -190,7 +190,7 @@ void main() { }); expect( - db.readVectorDoubles('Collection', 'value_float'), + db.readVectorFloats('Collection', 'value_float'), equals([ [1.5, 2.5, 3.5], [10.5, 20.5], @@ -212,7 +212,7 @@ void main() { db.createElement('Configuration', {'label': 'Test Config'}); expect(db.readVectorIntegers('Collection', 'value_int'), isEmpty); - expect(db.readVectorDoubles('Collection', 'value_float'), isEmpty); + expect(db.readVectorFloats('Collection', 'value_float'), isEmpty); } finally { db.close(); } @@ -427,7 +427,7 @@ void main() { }); }); - group('Read Scalar Doubles by ID', () { + group('Read Scalar Floats by ID', () { test('reads double by specific element ID', () { final db = Database.fromSchema( ':memory:', @@ -500,7 +500,7 @@ void main() { }); }); - group('Read Vector Doubles by ID', () { + group('Read Vector Floats by ID', () { test('reads double vector by specific element ID', () { final db = Database.fromSchema( ':memory:', @@ -513,7 +513,7 @@ void main() { 'value_float': [1.5, 2.5, 3.5], }); - expect(db.readVectorDoublesById('Collection', 'value_float', 1), equals([1.5, 2.5, 3.5])); + expect(db.readVectorFloatsById('Collection', 'value_float', 1), equals([1.5, 2.5, 3.5])); } finally { db.close(); } @@ -748,14 +748,14 @@ void main() { } }); - test('throws on nonexistent collection for doubles', () { + test('throws on nonexistent collection for floats', () { final db = Database.fromSchema( ':memory:', path.join(testsPath, 'schemas', 'valid', 'basic.sql'), ); try { expect( - () => db.readScalarDoubles('NonexistentCollection', 'value'), + () => db.readScalarFloats('NonexistentCollection', 'value'), throwsA(isA()), ); } finally { @@ -795,14 +795,14 @@ void main() { } }); - test('throws on nonexistent attribute for doubles', () { + test('throws on nonexistent attribute for floats', () { final db = Database.fromSchema( ':memory:', path.join(testsPath, 'schemas', 'valid', 'basic.sql'), ); try { expect( - () => db.readScalarDoubles('Configuration', 'nonexistent_attr'), + () => db.readScalarFloats('Configuration', 'nonexistent_attr'), throwsA(isA()), ); } finally { @@ -881,7 +881,7 @@ void main() { } }); - test('throws on nonexistent collection for vector doubles', () { + test('throws on nonexistent collection for vector floats', () { final db = Database.fromSchema( ':memory:', path.join(testsPath, 'schemas', 'valid', 'collections.sql'), @@ -889,7 +889,7 @@ void main() { try { db.createElement('Configuration', {'label': 'Test Config'}); expect( - () => db.readVectorDoubles('NonexistentCollection', 'value_float'), + () => db.readVectorFloats('NonexistentCollection', 'value_float'), throwsA(isA()), ); } finally { diff --git a/bindings/dart/test/update_test.dart b/bindings/dart/test/update_test.dart index 76e289a..5fb73e3 100644 --- a/bindings/dart/test/update_test.dart +++ b/bindings/dart/test/update_test.dart @@ -618,7 +618,7 @@ void main() { }); }); - group('Update Vector Doubles', () { + group('Update Vector Floats', () { test('replace existing vector', () { final db = Database.fromSchema( ':memory:', @@ -631,9 +631,9 @@ void main() { 'value_float': [1.5, 2.5, 3.5] }); - db.updateVectorDoubles('Collection', 'value_float', 1, [10.5, 20.5]); + db.updateVectorFloats('Collection', 'value_float', 1, [10.5, 20.5]); - final values = db.readVectorDoublesById('Collection', 'value_float', 1); + final values = db.readVectorFloatsById('Collection', 'value_float', 1); expect(values, equals([10.5, 20.5])); } finally { db.close(); @@ -652,9 +652,9 @@ void main() { 'value_float': [1.0] }); - db.updateVectorDoubles('Collection', 'value_float', 1, [1.23456789, 9.87654321]); + db.updateVectorFloats('Collection', 'value_float', 1, [1.23456789, 9.87654321]); - final values = db.readVectorDoublesById('Collection', 'value_float', 1); + final values = db.readVectorFloatsById('Collection', 'value_float', 1); expect(values[0], closeTo(1.23456789, 1e-8)); expect(values[1], closeTo(9.87654321, 1e-8)); } finally { @@ -674,9 +674,9 @@ void main() { 'value_float': [1.5, 2.5, 3.5] }); - db.updateVectorDoubles('Collection', 'value_float', 1, []); + db.updateVectorFloats('Collection', 'value_float', 1, []); - final values = db.readVectorDoublesById('Collection', 'value_float', 1); + final values = db.readVectorFloatsById('Collection', 'value_float', 1); expect(values, isEmpty); } finally { db.close(); diff --git a/bindings/julia/src/c_api.jl b/bindings/julia/src/c_api.jl index ffe6f47..b776620 100644 --- a/bindings/julia/src/c_api.jl +++ b/bindings/julia/src/c_api.jl @@ -134,8 +134,8 @@ function psr_database_read_scalar_integers(db, collection, attribute, out_values @ccall libpsr_database_c.psr_database_read_scalar_integers(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_values::Ptr{Ptr{Int64}}, out_count::Ptr{Csize_t})::psr_error_t end -function psr_database_read_scalar_doubles(db, collection, attribute, out_values, out_count) - @ccall libpsr_database_c.psr_database_read_scalar_doubles(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_values::Ptr{Ptr{Cdouble}}, out_count::Ptr{Csize_t})::psr_error_t +function psr_database_read_scalar_floats(db, collection, attribute, out_values, out_count) + @ccall libpsr_database_c.psr_database_read_scalar_floats(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_values::Ptr{Ptr{Cdouble}}, out_count::Ptr{Csize_t})::psr_error_t end function psr_database_read_scalar_strings(db, collection, attribute, out_values, out_count) @@ -146,8 +146,8 @@ function psr_database_read_vector_integers(db, collection, attribute, out_vector @ccall libpsr_database_c.psr_database_read_vector_integers(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_vectors::Ptr{Ptr{Ptr{Int64}}}, out_sizes::Ptr{Ptr{Csize_t}}, out_count::Ptr{Csize_t})::psr_error_t end -function psr_database_read_vector_doubles(db, collection, attribute, out_vectors, out_sizes, out_count) - @ccall libpsr_database_c.psr_database_read_vector_doubles(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_vectors::Ptr{Ptr{Ptr{Cdouble}}}, out_sizes::Ptr{Ptr{Csize_t}}, out_count::Ptr{Csize_t})::psr_error_t +function psr_database_read_vector_floats(db, collection, attribute, out_vectors, out_sizes, out_count) + @ccall libpsr_database_c.psr_database_read_vector_floats(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_vectors::Ptr{Ptr{Ptr{Cdouble}}}, out_sizes::Ptr{Ptr{Csize_t}}, out_count::Ptr{Csize_t})::psr_error_t end function psr_database_read_vector_strings(db, collection, attribute, out_vectors, out_sizes, out_count) @@ -158,8 +158,8 @@ function psr_database_read_set_integers(db, collection, attribute, out_sets, out @ccall libpsr_database_c.psr_database_read_set_integers(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_sets::Ptr{Ptr{Ptr{Int64}}}, out_sizes::Ptr{Ptr{Csize_t}}, out_count::Ptr{Csize_t})::psr_error_t end -function psr_database_read_set_doubles(db, collection, attribute, out_sets, out_sizes, out_count) - @ccall libpsr_database_c.psr_database_read_set_doubles(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_sets::Ptr{Ptr{Ptr{Cdouble}}}, out_sizes::Ptr{Ptr{Csize_t}}, out_count::Ptr{Csize_t})::psr_error_t +function psr_database_read_set_floats(db, collection, attribute, out_sets, out_sizes, out_count) + @ccall libpsr_database_c.psr_database_read_set_floats(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, out_sets::Ptr{Ptr{Ptr{Cdouble}}}, out_sizes::Ptr{Ptr{Csize_t}}, out_count::Ptr{Csize_t})::psr_error_t end function psr_database_read_set_strings(db, collection, attribute, out_sets, out_sizes, out_count) @@ -170,8 +170,8 @@ function psr_database_read_scalar_integers_by_id(db, collection, attribute, id, @ccall libpsr_database_c.psr_database_read_scalar_integers_by_id(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, out_value::Ptr{Int64}, out_has_value::Ptr{Cint})::psr_error_t end -function psr_database_read_scalar_doubles_by_id(db, collection, attribute, id, out_value, out_has_value) - @ccall libpsr_database_c.psr_database_read_scalar_doubles_by_id(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, out_value::Ptr{Cdouble}, out_has_value::Ptr{Cint})::psr_error_t +function psr_database_read_scalar_floats_by_id(db, collection, attribute, id, out_value, out_has_value) + @ccall libpsr_database_c.psr_database_read_scalar_floats_by_id(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, out_value::Ptr{Cdouble}, out_has_value::Ptr{Cint})::psr_error_t end function psr_database_read_scalar_strings_by_id(db, collection, attribute, id, out_value, out_has_value) @@ -182,8 +182,8 @@ function psr_database_read_vector_integers_by_id(db, collection, attribute, id, @ccall libpsr_database_c.psr_database_read_vector_integers_by_id(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, out_values::Ptr{Ptr{Int64}}, out_count::Ptr{Csize_t})::psr_error_t end -function psr_database_read_vector_doubles_by_id(db, collection, attribute, id, out_values, out_count) - @ccall libpsr_database_c.psr_database_read_vector_doubles_by_id(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, out_values::Ptr{Ptr{Cdouble}}, out_count::Ptr{Csize_t})::psr_error_t +function psr_database_read_vector_floats_by_id(db, collection, attribute, id, out_values, out_count) + @ccall libpsr_database_c.psr_database_read_vector_floats_by_id(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, out_values::Ptr{Ptr{Cdouble}}, out_count::Ptr{Csize_t})::psr_error_t end function psr_database_read_vector_strings_by_id(db, collection, attribute, id, out_values, out_count) @@ -194,8 +194,8 @@ function psr_database_read_set_integers_by_id(db, collection, attribute, id, out @ccall libpsr_database_c.psr_database_read_set_integers_by_id(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, out_values::Ptr{Ptr{Int64}}, out_count::Ptr{Csize_t})::psr_error_t end -function psr_database_read_set_doubles_by_id(db, collection, attribute, id, out_values, out_count) - @ccall libpsr_database_c.psr_database_read_set_doubles_by_id(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, out_values::Ptr{Ptr{Cdouble}}, out_count::Ptr{Csize_t})::psr_error_t +function psr_database_read_set_floats_by_id(db, collection, attribute, id, out_values, out_count) + @ccall libpsr_database_c.psr_database_read_set_floats_by_id(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, out_values::Ptr{Ptr{Cdouble}}, out_count::Ptr{Csize_t})::psr_error_t end function psr_database_read_set_strings_by_id(db, collection, attribute, id, out_values, out_count) @@ -226,8 +226,8 @@ function psr_database_update_vector_integers(db, collection, attribute, id, valu @ccall libpsr_database_c.psr_database_update_vector_integers(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, values::Ptr{Int64}, count::Csize_t)::psr_error_t end -function psr_database_update_vector_doubles(db, collection, attribute, id, values, count) - @ccall libpsr_database_c.psr_database_update_vector_doubles(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, values::Ptr{Cdouble}, count::Csize_t)::psr_error_t +function psr_database_update_vector_floats(db, collection, attribute, id, values, count) + @ccall libpsr_database_c.psr_database_update_vector_floats(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, values::Ptr{Cdouble}, count::Csize_t)::psr_error_t end function psr_database_update_vector_strings(db, collection, attribute, id, values, count) @@ -238,8 +238,8 @@ function psr_database_update_set_integers(db, collection, attribute, id, values, @ccall libpsr_database_c.psr_database_update_set_integers(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, values::Ptr{Int64}, count::Csize_t)::psr_error_t end -function psr_database_update_set_doubles(db, collection, attribute, id, values, count) - @ccall libpsr_database_c.psr_database_update_set_doubles(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, values::Ptr{Cdouble}, count::Csize_t)::psr_error_t +function psr_database_update_set_floats(db, collection, attribute, id, values, count) + @ccall libpsr_database_c.psr_database_update_set_floats(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, values::Ptr{Cdouble}, count::Csize_t)::psr_error_t end function psr_database_update_set_strings(db, collection, attribute, id, values, count) diff --git a/bindings/julia/src/database_read.jl b/bindings/julia/src/database_read.jl index 2edc9ca..e0e0c8b 100644 --- a/bindings/julia/src/database_read.jl +++ b/bindings/julia/src/database_read.jl @@ -45,13 +45,13 @@ function read_scalar_integers(db::Database, collection::String, attribute::Strin return result end -function read_scalar_doubles(db::Database, collection::String, attribute::String) +function read_scalar_floats(db::Database, collection::String, attribute::String) out_values = Ref{Ptr{Float64}}(C_NULL) out_count = Ref{Csize_t}(0) - err = C.psr_database_read_scalar_doubles(db.ptr, collection, attribute, out_values, out_count) + err = C.psr_database_read_scalar_floats(db.ptr, collection, attribute, out_values, out_count) if err != C.PSR_OK - throw(DatabaseException("Failed to read scalar doubles from '$collection.$attribute'")) + throw(DatabaseException("Failed to read scalar floats from '$collection.$attribute'")) end count = out_count[] @@ -113,14 +113,14 @@ function read_vector_integers(db::Database, collection::String, attribute::Strin return result end -function read_vector_doubles(db::Database, collection::String, attribute::String) +function read_vector_floats(db::Database, collection::String, attribute::String) out_vectors = Ref{Ptr{Ptr{Cdouble}}}(C_NULL) out_sizes = Ref{Ptr{Csize_t}}(C_NULL) out_count = Ref{Csize_t}(0) - err = C.psr_database_read_vector_doubles(db.ptr, collection, attribute, out_vectors, out_sizes, out_count) + err = C.psr_database_read_vector_floats(db.ptr, collection, attribute, out_vectors, out_sizes, out_count) if err != C.PSR_OK - throw(DatabaseException("Failed to read vector doubles from '$collection.$attribute'")) + throw(DatabaseException("Failed to read vector floats from '$collection.$attribute'")) end count = out_count[] @@ -201,14 +201,14 @@ function read_set_integers(db::Database, collection::String, attribute::String) return result end -function read_set_doubles(db::Database, collection::String, attribute::String) +function read_set_floats(db::Database, collection::String, attribute::String) out_sets = Ref{Ptr{Ptr{Cdouble}}}(C_NULL) out_sizes = Ref{Ptr{Csize_t}}(C_NULL) out_count = Ref{Csize_t}(0) - err = C.psr_database_read_set_doubles(db.ptr, collection, attribute, out_sets, out_sizes, out_count) + err = C.psr_database_read_set_floats(db.ptr, collection, attribute, out_sets, out_sizes, out_count) if err != C.PSR_OK - throw(DatabaseException("Failed to read set doubles from '$collection.$attribute'")) + throw(DatabaseException("Failed to read set floats from '$collection.$attribute'")) end count = out_count[] @@ -277,11 +277,11 @@ function read_scalar_integers_by_id(db::Database, collection::String, attribute: return out_value[] end -function read_scalar_doubles_by_id(db::Database, collection::String, attribute::String, id::Int64) +function read_scalar_floats_by_id(db::Database, collection::String, attribute::String, id::Int64) out_value = Ref{Float64}(0.0) out_has_value = Ref{Cint}(0) - err = C.psr_database_read_scalar_doubles_by_id(db.ptr, collection, attribute, id, out_value, out_has_value) + err = C.psr_database_read_scalar_floats_by_id(db.ptr, collection, attribute, id, out_value, out_has_value) if err != C.PSR_OK throw(DatabaseException("Failed to read scalar double by id from '$collection.$attribute'")) end @@ -330,13 +330,13 @@ function read_vector_integers_by_id(db::Database, collection::String, attribute: return result end -function read_vector_doubles_by_id(db::Database, collection::String, attribute::String, id::Int64) +function read_vector_floats_by_id(db::Database, collection::String, attribute::String, id::Int64) out_values = Ref{Ptr{Float64}}(C_NULL) out_count = Ref{Csize_t}(0) - err = C.psr_database_read_vector_doubles_by_id(db.ptr, collection, attribute, id, out_values, out_count) + err = C.psr_database_read_vector_floats_by_id(db.ptr, collection, attribute, id, out_values, out_count) if err != C.PSR_OK - throw(DatabaseException("Failed to read vector doubles by id from '$collection.$attribute'")) + throw(DatabaseException("Failed to read vector floats by id from '$collection.$attribute'")) end count = out_count[] @@ -390,13 +390,13 @@ function read_set_integers_by_id(db::Database, collection::String, attribute::St return result end -function read_set_doubles_by_id(db::Database, collection::String, attribute::String, id::Int64) +function read_set_floats_by_id(db::Database, collection::String, attribute::String, id::Int64) out_values = Ref{Ptr{Float64}}(C_NULL) out_count = Ref{Csize_t}(0) - err = C.psr_database_read_set_doubles_by_id(db.ptr, collection, attribute, id, out_values, out_count) + err = C.psr_database_read_set_floats_by_id(db.ptr, collection, attribute, id, out_values, out_count) if err != C.PSR_OK - throw(DatabaseException("Failed to read set doubles by id from '$collection.$attribute'")) + throw(DatabaseException("Failed to read set floats by id from '$collection.$attribute'")) end count = out_count[] @@ -467,7 +467,7 @@ function read(db::Database, collection::String, attribute::String) if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_scalar_integers(db, collection, attribute) elseif attribute_type.data_type == C.PSR_DATA_TYPE_FLOAT - return read_scalar_doubles(db, collection, attribute) + return read_scalar_floats(db, collection, attribute) elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_scalar_strings(db, collection, attribute) else @@ -477,7 +477,7 @@ function read(db::Database, collection::String, attribute::String) if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_vector_integers(db, collection, attribute) elseif attribute_type.data_type == C.PSR_DATA_TYPE_FLOAT - return read_vector_doubles(db, collection, attribute) + return read_vector_floats(db, collection, attribute) elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_vector_strings(db, collection, attribute) else @@ -487,7 +487,7 @@ function read(db::Database, collection::String, attribute::String) if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_set_integers(db, collection, attribute) elseif attribute_type.data_type == C.PSR_DATA_TYPE_FLOAT - return read_set_doubles(db, collection, attribute) + return read_set_floats(db, collection, attribute) elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_set_strings(db, collection, attribute) else @@ -505,7 +505,7 @@ function read_by_id(db::Database, collection::String, attribute::String, id::Int if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_scalar_integers_by_id(db, collection, attribute, id) elseif attribute_type.data_type == C.PSR_DATA_TYPE_FLOAT - return read_scalar_doubles_by_id(db, collection, attribute, id) + return read_scalar_floats_by_id(db, collection, attribute, id) elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_scalar_strings_by_id(db, collection, attribute, id) else @@ -515,7 +515,7 @@ function read_by_id(db::Database, collection::String, attribute::String, id::Int if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_vector_integers_by_id(db, collection, attribute, id) elseif attribute_type.data_type == C.PSR_DATA_TYPE_FLOAT - return read_vector_doubles_by_id(db, collection, attribute, id) + return read_vector_floats_by_id(db, collection, attribute, id) elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_vector_strings_by_id(db, collection, attribute, id) else @@ -525,7 +525,7 @@ function read_by_id(db::Database, collection::String, attribute::String, id::Int if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER return read_set_integers_by_id(db, collection, attribute, id) elseif attribute_type.data_type == C.PSR_DATA_TYPE_FLOAT - return read_set_doubles_by_id(db, collection, attribute, id) + return read_set_floats_by_id(db, collection, attribute, id) elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_set_strings_by_id(db, collection, attribute, id) else diff --git a/bindings/julia/src/database_update.jl b/bindings/julia/src/database_update.jl index e0c164e..0f70452 100644 --- a/bindings/julia/src/database_update.jl +++ b/bindings/julia/src/database_update.jl @@ -69,9 +69,9 @@ function update_vector_integers!( return nothing end -function update_vector_doubles!(db::Database, collection::String, attribute::String, id::Int64, values::Vector{<:Real}) +function update_vector_floats!(db::Database, collection::String, attribute::String, id::Int64, values::Vector{<:Real}) float_values = Float64[Float64(v) for v in values] - err = C.psr_database_update_vector_doubles( + err = C.psr_database_update_vector_floats( db.ptr, collection, attribute, @@ -80,7 +80,7 @@ function update_vector_doubles!(db::Database, collection::String, attribute::Str Csize_t(length(float_values)), ) if err != C.PSR_OK - throw(DatabaseException("Failed to update vector doubles '$collection.$attribute' for id $id")) + throw(DatabaseException("Failed to update vector floats '$collection.$attribute' for id $id")) end return nothing end @@ -114,9 +114,9 @@ function update_set_integers!(db::Database, collection::String, attribute::Strin return nothing end -function update_set_doubles!(db::Database, collection::String, attribute::String, id::Int64, values::Vector{<:Real}) +function update_set_floats!(db::Database, collection::String, attribute::String, id::Int64, values::Vector{<:Real}) float_values = Float64[Float64(v) for v in values] - err = C.psr_database_update_set_doubles( + err = C.psr_database_update_set_floats( db.ptr, collection, attribute, @@ -125,7 +125,7 @@ function update_set_doubles!(db::Database, collection::String, attribute::String Csize_t(length(float_values)), ) if err != C.PSR_OK - throw(DatabaseException("Failed to update set doubles '$collection.$attribute' for id $id")) + throw(DatabaseException("Failed to update set floats '$collection.$attribute' for id $id")) end return nothing end diff --git a/bindings/julia/test/test_create.jl b/bindings/julia/test/test_create.jl index 6ea9a14..2bf7f88 100644 --- a/bindings/julia/test/test_create.jl +++ b/bindings/julia/test/test_create.jl @@ -215,7 +215,7 @@ include("fixture.jl") PSRDatabase.create_element!(db, "Collection"; label = "Item 1", value_float = [1.1, 2.2, 3.3]) - result = PSRDatabase.read_vector_doubles_by_id(db, "Collection", "value_float", Int64(1)) + result = PSRDatabase.read_vector_floats_by_id(db, "Collection", "value_float", Int64(1)) @test length(result) == 3 @test result == [1.1, 2.2, 3.3] diff --git a/bindings/julia/test/test_lua_runner.jl b/bindings/julia/test/test_lua_runner.jl index b87a53b..2f4ef6f 100644 --- a/bindings/julia/test/test_lua_runner.jl +++ b/bindings/julia/test/test_lua_runner.jl @@ -172,7 +172,7 @@ include("fixture.jl") PSRDatabase.close!(db) end - @testset "Read Doubles" begin + @testset "Read Floats" begin path_schema = joinpath(tests_path(), "schemas", "valid", "collections.sql") db = PSRDatabase.from_schema(":memory:", path_schema) @@ -185,8 +185,8 @@ include("fixture.jl") PSRDatabase.run!( lua, """ - local floats = db:read_scalar_doubles("Collection", "some_float") - assert(#floats == 2, "Expected 2 doubles") + local floats = db:read_scalar_floats("Collection", "some_float") + assert(#floats == 2, "Expected 2 floats") assert(floats[1] == 1.5, "First double mismatch") assert(floats[2] == 2.5, "Second double mismatch") """, diff --git a/bindings/julia/test/test_read.jl b/bindings/julia/test/test_read.jl index a40c8f8..3e7620a 100644 --- a/bindings/julia/test/test_read.jl +++ b/bindings/julia/test/test_read.jl @@ -25,7 +25,7 @@ include("fixture.jl") @test PSRDatabase.read_scalar_strings(db, "Configuration", "label") == ["Config 1", "Config 2"] @test PSRDatabase.read_scalar_integers(db, "Configuration", "integer_attribute") == [42, 100] - @test PSRDatabase.read_scalar_doubles(db, "Configuration", "float_attribute") == [3.14, 2.71] + @test PSRDatabase.read_scalar_floats(db, "Configuration", "float_attribute") == [3.14, 2.71] @test PSRDatabase.read_scalar_strings(db, "Configuration", "string_attribute") == ["hello", "world"] PSRDatabase.close!(db) @@ -41,7 +41,7 @@ include("fixture.jl") @test PSRDatabase.read_scalar_strings(db, "Collection", "label") == ["Item 1", "Item 2"] @test PSRDatabase.read_scalar_integers(db, "Collection", "some_integer") == [10, 20] - @test PSRDatabase.read_scalar_doubles(db, "Collection", "some_float") == [1.5, 2.5] + @test PSRDatabase.read_scalar_floats(db, "Collection", "some_float") == [1.5, 2.5] PSRDatabase.close!(db) end @@ -55,7 +55,7 @@ include("fixture.jl") # No Collection elements created @test PSRDatabase.read_scalar_strings(db, "Collection", "label") == String[] @test PSRDatabase.read_scalar_integers(db, "Collection", "some_integer") == Int64[] - @test PSRDatabase.read_scalar_doubles(db, "Collection", "some_float") == Float64[] + @test PSRDatabase.read_scalar_floats(db, "Collection", "some_float") == Float64[] PSRDatabase.close!(db) end @@ -81,7 +81,7 @@ include("fixture.jl") ) @test PSRDatabase.read_vector_integers(db, "Collection", "value_int") == [[1, 2, 3], [10, 20]] - @test PSRDatabase.read_vector_doubles(db, "Collection", "value_float") == [[1.5, 2.5, 3.5], [10.5, 20.5]] + @test PSRDatabase.read_vector_floats(db, "Collection", "value_float") == [[1.5, 2.5, 3.5], [10.5, 20.5]] PSRDatabase.close!(db) end @@ -94,7 +94,7 @@ include("fixture.jl") # No Collection elements created @test PSRDatabase.read_vector_integers(db, "Collection", "value_int") == Vector{Int64}[] - @test PSRDatabase.read_vector_doubles(db, "Collection", "value_float") == Vector{Float64}[] + @test PSRDatabase.read_vector_floats(db, "Collection", "value_float") == Vector{Float64}[] PSRDatabase.close!(db) end @@ -250,15 +250,15 @@ include("fixture.jl") PSRDatabase.close!(db) end - @testset "Scalar Doubles by ID" begin + @testset "Scalar Floats by ID" begin path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") db = PSRDatabase.from_schema(":memory:", path_schema) PSRDatabase.create_element!(db, "Configuration"; label = "Config 1", float_attribute = 3.14) PSRDatabase.create_element!(db, "Configuration"; label = "Config 2", float_attribute = 2.71) - @test PSRDatabase.read_scalar_doubles_by_id(db, "Configuration", "float_attribute", 1) == 3.14 - @test PSRDatabase.read_scalar_doubles_by_id(db, "Configuration", "float_attribute", 2) == 2.71 + @test PSRDatabase.read_scalar_floats_by_id(db, "Configuration", "float_attribute", 1) == 3.14 + @test PSRDatabase.read_scalar_floats_by_id(db, "Configuration", "float_attribute", 2) == 2.71 PSRDatabase.close!(db) end @@ -290,14 +290,14 @@ include("fixture.jl") PSRDatabase.close!(db) end - @testset "Vector Doubles by ID" begin + @testset "Vector Floats by ID" begin path_schema = joinpath(tests_path(), "schemas", "valid", "collections.sql") db = PSRDatabase.from_schema(":memory:", path_schema) PSRDatabase.create_element!(db, "Configuration"; label = "Test Config") PSRDatabase.create_element!(db, "Collection"; label = "Item 1", value_float = [1.5, 2.5, 3.5]) - @test PSRDatabase.read_vector_doubles_by_id(db, "Collection", "value_float", 1) == [1.5, 2.5, 3.5] + @test PSRDatabase.read_vector_floats_by_id(db, "Collection", "value_float", 1) == [1.5, 2.5, 3.5] PSRDatabase.close!(db) end @@ -450,7 +450,7 @@ include("fixture.jl") "NonexistentCollection", "value", ) - @test_throws PSRDatabase.DatabaseException PSRDatabase.read_scalar_doubles(db, "NonexistentCollection", "value") + @test_throws PSRDatabase.DatabaseException PSRDatabase.read_scalar_floats(db, "NonexistentCollection", "value") PSRDatabase.close!(db) end @@ -469,7 +469,7 @@ include("fixture.jl") "Configuration", "nonexistent_attr", ) - @test_throws PSRDatabase.DatabaseException PSRDatabase.read_scalar_doubles( + @test_throws PSRDatabase.DatabaseException PSRDatabase.read_scalar_floats( db, "Configuration", "nonexistent_attr", @@ -486,7 +486,7 @@ include("fixture.jl") # Read by ID that doesn't exist returns nothing @test PSRDatabase.read_scalar_integers_by_id(db, "Configuration", "integer_attribute", 999) === nothing - @test PSRDatabase.read_scalar_doubles_by_id(db, "Configuration", "float_attribute", 999) === nothing + @test PSRDatabase.read_scalar_floats_by_id(db, "Configuration", "float_attribute", 999) === nothing @test PSRDatabase.read_scalar_strings_by_id(db, "Configuration", "string_attribute", 999) === nothing PSRDatabase.close!(db) @@ -503,7 +503,7 @@ include("fixture.jl") "NonexistentCollection", "value_int", ) - @test_throws PSRDatabase.DatabaseException PSRDatabase.read_vector_doubles( + @test_throws PSRDatabase.DatabaseException PSRDatabase.read_vector_floats( db, "NonexistentCollection", "value_float", diff --git a/bindings/julia/test/test_update.jl b/bindings/julia/test/test_update.jl index e9750aa..f6142f4 100644 --- a/bindings/julia/test/test_update.jl +++ b/bindings/julia/test/test_update.jl @@ -48,7 +48,7 @@ include("fixture.jl") int_value = PSRDatabase.read_scalar_integers_by_id(db, "Configuration", "integer_attribute", Int64(1)) @test int_value == 500 - float_value = PSRDatabase.read_scalar_doubles_by_id(db, "Configuration", "float_attribute", Int64(1)) + float_value = PSRDatabase.read_scalar_floats_by_id(db, "Configuration", "float_attribute", Int64(1)) @test float_value == 9.9 # Verify label unchanged @@ -202,7 +202,7 @@ include("fixture.jl") PSRDatabase.update_element!(db, "Configuration", Int64(1); float_attribute = 99.99) - value = PSRDatabase.read_scalar_doubles_by_id(db, "Configuration", "float_attribute", Int64(1)) + value = PSRDatabase.read_scalar_floats_by_id(db, "Configuration", "float_attribute", Int64(1)) @test value == 99.99 PSRDatabase.close!(db) @@ -280,17 +280,17 @@ include("fixture.jl") # Basic update PSRDatabase.update_scalar_double!(db, "Configuration", "float_attribute", Int64(1), 2.71) - value = PSRDatabase.read_scalar_doubles_by_id(db, "Configuration", "float_attribute", Int64(1)) + value = PSRDatabase.read_scalar_floats_by_id(db, "Configuration", "float_attribute", Int64(1)) @test value == 2.71 # Update to 0.0 PSRDatabase.update_scalar_double!(db, "Configuration", "float_attribute", Int64(1), 0.0) - value = PSRDatabase.read_scalar_doubles_by_id(db, "Configuration", "float_attribute", Int64(1)) + value = PSRDatabase.read_scalar_floats_by_id(db, "Configuration", "float_attribute", Int64(1)) @test value == 0.0 # Precision test PSRDatabase.update_scalar_double!(db, "Configuration", "float_attribute", Int64(1), 1.23456789012345) - value = PSRDatabase.read_scalar_doubles_by_id(db, "Configuration", "float_attribute", Int64(1)) + value = PSRDatabase.read_scalar_floats_by_id(db, "Configuration", "float_attribute", Int64(1)) @test value ≈ 1.23456789012345 PSRDatabase.close!(db) @@ -388,7 +388,7 @@ include("fixture.jl") PSRDatabase.close!(db) end - @testset "Vector Doubles" begin + @testset "Vector Floats" begin path_schema = joinpath(tests_path(), "schemas", "valid", "collections.sql") db = PSRDatabase.from_schema(":memory:", path_schema) @@ -396,18 +396,18 @@ include("fixture.jl") PSRDatabase.create_element!(db, "Collection"; label = "Item 1", value_float = [1.5, 2.5, 3.5]) # Replace existing vector - PSRDatabase.update_vector_doubles!(db, "Collection", "value_float", Int64(1), [10.5, 20.5]) - values = PSRDatabase.read_vector_doubles_by_id(db, "Collection", "value_float", Int64(1)) + PSRDatabase.update_vector_floats!(db, "Collection", "value_float", Int64(1), [10.5, 20.5]) + values = PSRDatabase.read_vector_floats_by_id(db, "Collection", "value_float", Int64(1)) @test values == [10.5, 20.5] # Precision test - PSRDatabase.update_vector_doubles!(db, "Collection", "value_float", Int64(1), [1.23456789, 9.87654321]) - values = PSRDatabase.read_vector_doubles_by_id(db, "Collection", "value_float", Int64(1)) + PSRDatabase.update_vector_floats!(db, "Collection", "value_float", Int64(1), [1.23456789, 9.87654321]) + values = PSRDatabase.read_vector_floats_by_id(db, "Collection", "value_float", Int64(1)) @test values ≈ [1.23456789, 9.87654321] # Update to empty vector - PSRDatabase.update_vector_doubles!(db, "Collection", "value_float", Int64(1), Float64[]) - values = PSRDatabase.read_vector_doubles_by_id(db, "Collection", "value_float", Int64(1)) + PSRDatabase.update_vector_floats!(db, "Collection", "value_float", Int64(1), Float64[]) + values = PSRDatabase.read_vector_floats_by_id(db, "Collection", "value_float", Int64(1)) @test isempty(values) PSRDatabase.close!(db) diff --git a/include/psr/c/database.h b/include/psr/c/database.h index d0f4ac2..aaacbe4 100644 --- a/include/psr/c/database.h +++ b/include/psr/c/database.h @@ -80,7 +80,7 @@ PSR_C_API psr_error_t psr_database_read_scalar_integers(psr_database_t* db, int64_t** out_values, size_t* out_count); -PSR_C_API psr_error_t psr_database_read_scalar_doubles(psr_database_t* db, +PSR_C_API psr_error_t psr_database_read_scalar_floats(psr_database_t* db, const char* collection, const char* attribute, double** out_values, @@ -100,7 +100,7 @@ PSR_C_API psr_error_t psr_database_read_vector_integers(psr_database_t* db, size_t** out_sizes, size_t* out_count); -PSR_C_API psr_error_t psr_database_read_vector_doubles(psr_database_t* db, +PSR_C_API psr_error_t psr_database_read_vector_floats(psr_database_t* db, const char* collection, const char* attribute, double*** out_vectors, @@ -122,7 +122,7 @@ PSR_C_API psr_error_t psr_database_read_set_integers(psr_database_t* db, size_t** out_sizes, size_t* out_count); -PSR_C_API psr_error_t psr_database_read_set_doubles(psr_database_t* db, +PSR_C_API psr_error_t psr_database_read_set_floats(psr_database_t* db, const char* collection, const char* attribute, double*** out_sets, @@ -144,7 +144,7 @@ PSR_C_API psr_error_t psr_database_read_scalar_integers_by_id(psr_database_t* db int64_t* out_value, int* out_has_value); -PSR_C_API psr_error_t psr_database_read_scalar_doubles_by_id(psr_database_t* db, +PSR_C_API psr_error_t psr_database_read_scalar_floats_by_id(psr_database_t* db, const char* collection, const char* attribute, int64_t id, @@ -166,7 +166,7 @@ PSR_C_API psr_error_t psr_database_read_vector_integers_by_id(psr_database_t* db int64_t** out_values, size_t* out_count); -PSR_C_API psr_error_t psr_database_read_vector_doubles_by_id(psr_database_t* db, +PSR_C_API psr_error_t psr_database_read_vector_floats_by_id(psr_database_t* db, const char* collection, const char* attribute, int64_t id, @@ -188,7 +188,7 @@ PSR_C_API psr_error_t psr_database_read_set_integers_by_id(psr_database_t* db, int64_t** out_values, size_t* out_count); -PSR_C_API psr_error_t psr_database_read_set_doubles_by_id(psr_database_t* db, +PSR_C_API psr_error_t psr_database_read_set_floats_by_id(psr_database_t* db, const char* collection, const char* attribute, int64_t id, @@ -242,7 +242,7 @@ PSR_C_API psr_error_t psr_database_update_vector_integers(psr_database_t* db, const int64_t* values, size_t count); -PSR_C_API psr_error_t psr_database_update_vector_doubles(psr_database_t* db, +PSR_C_API psr_error_t psr_database_update_vector_floats(psr_database_t* db, const char* collection, const char* attribute, int64_t id, @@ -264,7 +264,7 @@ PSR_C_API psr_error_t psr_database_update_set_integers(psr_database_t* db, const int64_t* values, size_t count); -PSR_C_API psr_error_t psr_database_update_set_doubles(psr_database_t* db, +PSR_C_API psr_error_t psr_database_update_set_floats(psr_database_t* db, const char* collection, const char* attribute, int64_t id, diff --git a/include/psr/database.h b/include/psr/database.h index f087085..daa6bb3 100644 --- a/include/psr/database.h +++ b/include/psr/database.h @@ -58,20 +58,20 @@ class PSR_API Database { // Read scalar attributes (all elements) std::vector read_scalar_integers(const std::string& collection, const std::string& attribute); - std::vector read_scalar_doubles(const std::string& collection, const std::string& attribute); + std::vector read_scalar_floats(const std::string& collection, const std::string& attribute); std::vector read_scalar_strings(const std::string& collection, const std::string& attribute); // Read scalar attributes (by element ID) std::optional read_scalar_integers_by_id(const std::string& collection, const std::string& attribute, int64_t id); std::optional - read_scalar_doubles_by_id(const std::string& collection, const std::string& attribute, int64_t id); + read_scalar_floats_by_id(const std::string& collection, const std::string& attribute, int64_t id); std::optional read_scalar_strings_by_id(const std::string& collection, const std::string& attribute, int64_t id); // Read vector attributes (all elements) std::vector> read_vector_integers(const std::string& collection, const std::string& attribute); - std::vector> read_vector_doubles(const std::string& collection, const std::string& attribute); + std::vector> read_vector_floats(const std::string& collection, const std::string& attribute); std::vector> read_vector_strings(const std::string& collection, const std::string& attribute); @@ -79,19 +79,19 @@ class PSR_API Database { std::vector read_vector_integers_by_id(const std::string& collection, const std::string& attribute, int64_t id); std::vector - read_vector_doubles_by_id(const std::string& collection, const std::string& attribute, int64_t id); + read_vector_floats_by_id(const std::string& collection, const std::string& attribute, int64_t id); std::vector read_vector_strings_by_id(const std::string& collection, const std::string& attribute, int64_t id); // Read set attributes (all elements) std::vector> read_set_integers(const std::string& collection, const std::string& attribute); - std::vector> read_set_doubles(const std::string& collection, const std::string& attribute); + std::vector> read_set_floats(const std::string& collection, const std::string& attribute); std::vector> read_set_strings(const std::string& collection, const std::string& attribute); // Read set attributes (by element ID) std::vector read_set_integers_by_id(const std::string& collection, const std::string& attribute, int64_t id); - std::vector read_set_doubles_by_id(const std::string& collection, const std::string& attribute, int64_t id); + std::vector read_set_floats_by_id(const std::string& collection, const std::string& attribute, int64_t id); std::vector read_set_strings_by_id(const std::string& collection, const std::string& attribute, int64_t id); @@ -114,7 +114,7 @@ class PSR_API Database { const std::string& attribute, int64_t id, const std::vector& values); - void update_vector_doubles(const std::string& collection, + void update_vector_floats(const std::string& collection, const std::string& attribute, int64_t id, const std::vector& values); @@ -128,7 +128,7 @@ class PSR_API Database { const std::string& attribute, int64_t id, const std::vector& values); - void update_set_doubles(const std::string& collection, + void update_set_floats(const std::string& collection, const std::string& attribute, int64_t id, const std::vector& values); diff --git a/src/c_api_database.cpp b/src/c_api_database.cpp index 2ca27da..e40ab3c 100644 --- a/src/c_api_database.cpp +++ b/src/c_api_database.cpp @@ -268,7 +268,7 @@ PSR_C_API psr_error_t psr_database_read_scalar_integers(psr_database_t* db, } } -PSR_C_API psr_error_t psr_database_read_scalar_doubles(psr_database_t* db, +PSR_C_API psr_error_t psr_database_read_scalar_floats(psr_database_t* db, const char* collection, const char* attribute, double** out_values, @@ -277,7 +277,7 @@ PSR_C_API psr_error_t psr_database_read_scalar_doubles(psr_database_t* db, return PSR_ERROR_INVALID_ARGUMENT; } try { - return read_scalars_impl(db->db.read_scalar_doubles(collection, attribute), out_values, out_count); + return read_scalars_impl(db->db.read_scalar_floats(collection, attribute), out_values, out_count); } catch (const std::exception&) { return PSR_ERROR_DATABASE; } @@ -345,7 +345,7 @@ PSR_C_API psr_error_t psr_database_read_vector_integers(psr_database_t* db, } } -PSR_C_API psr_error_t psr_database_read_vector_doubles(psr_database_t* db, +PSR_C_API psr_error_t psr_database_read_vector_floats(psr_database_t* db, const char* collection, const char* attribute, double*** out_vectors, @@ -355,7 +355,7 @@ PSR_C_API psr_error_t psr_database_read_vector_doubles(psr_database_t* db, return PSR_ERROR_INVALID_ARGUMENT; } try { - return read_vectors_impl(db->db.read_vector_doubles(collection, attribute), out_vectors, out_sizes, out_count); + return read_vectors_impl(db->db.read_vector_floats(collection, attribute), out_vectors, out_sizes, out_count); } catch (const std::exception&) { return PSR_ERROR_DATABASE; } @@ -441,7 +441,7 @@ PSR_C_API psr_error_t psr_database_read_set_integers(psr_database_t* db, } } -PSR_C_API psr_error_t psr_database_read_set_doubles(psr_database_t* db, +PSR_C_API psr_error_t psr_database_read_set_floats(psr_database_t* db, const char* collection, const char* attribute, double*** out_sets, @@ -451,7 +451,7 @@ PSR_C_API psr_error_t psr_database_read_set_doubles(psr_database_t* db, return PSR_ERROR_INVALID_ARGUMENT; } try { - return read_vectors_impl(db->db.read_set_doubles(collection, attribute), out_sets, out_sizes, out_count); + return read_vectors_impl(db->db.read_set_floats(collection, attribute), out_sets, out_sizes, out_count); } catch (const std::exception&) { return PSR_ERROR_DATABASE; } @@ -520,7 +520,7 @@ PSR_C_API psr_error_t psr_database_read_scalar_integers_by_id(psr_database_t* db } } -PSR_C_API psr_error_t psr_database_read_scalar_doubles_by_id(psr_database_t* db, +PSR_C_API psr_error_t psr_database_read_scalar_floats_by_id(psr_database_t* db, const char* collection, const char* attribute, int64_t id, @@ -530,7 +530,7 @@ PSR_C_API psr_error_t psr_database_read_scalar_doubles_by_id(psr_database_t* db, return PSR_ERROR_INVALID_ARGUMENT; } try { - auto result = db->db.read_scalar_doubles_by_id(collection, attribute, id); + auto result = db->db.read_scalar_floats_by_id(collection, attribute, id); if (result.has_value()) { *out_value = *result; *out_has_value = 1; @@ -588,7 +588,7 @@ PSR_C_API psr_error_t psr_database_read_vector_integers_by_id(psr_database_t* db } } -PSR_C_API psr_error_t psr_database_read_vector_doubles_by_id(psr_database_t* db, +PSR_C_API psr_error_t psr_database_read_vector_floats_by_id(psr_database_t* db, const char* collection, const char* attribute, int64_t id, @@ -598,7 +598,7 @@ PSR_C_API psr_error_t psr_database_read_vector_doubles_by_id(psr_database_t* db, return PSR_ERROR_INVALID_ARGUMENT; } try { - auto values = db->db.read_vector_doubles_by_id(collection, attribute, id); + auto values = db->db.read_vector_floats_by_id(collection, attribute, id); return read_scalars_impl(values, out_values, out_count); } catch (const std::exception&) { return PSR_ERROR_DATABASE; @@ -652,7 +652,7 @@ PSR_C_API psr_error_t psr_database_read_set_integers_by_id(psr_database_t* db, } } -PSR_C_API psr_error_t psr_database_read_set_doubles_by_id(psr_database_t* db, +PSR_C_API psr_error_t psr_database_read_set_floats_by_id(psr_database_t* db, const char* collection, const char* attribute, int64_t id, @@ -662,7 +662,7 @@ PSR_C_API psr_error_t psr_database_read_set_doubles_by_id(psr_database_t* db, return PSR_ERROR_INVALID_ARGUMENT; } try { - auto values = db->db.read_set_doubles_by_id(collection, attribute, id); + auto values = db->db.read_set_floats_by_id(collection, attribute, id); return read_scalars_impl(values, out_values, out_count); } catch (const std::exception&) { return PSR_ERROR_DATABASE; @@ -781,7 +781,7 @@ PSR_C_API psr_error_t psr_database_update_vector_integers(psr_database_t* db, } } -PSR_C_API psr_error_t psr_database_update_vector_doubles(psr_database_t* db, +PSR_C_API psr_error_t psr_database_update_vector_floats(psr_database_t* db, const char* collection, const char* attribute, int64_t id, @@ -792,7 +792,7 @@ PSR_C_API psr_error_t psr_database_update_vector_doubles(psr_database_t* db, } try { std::vector vec(values, values + count); - db->db.update_vector_doubles(collection, attribute, id, vec); + db->db.update_vector_floats(collection, attribute, id, vec); return PSR_OK; } catch (const std::exception&) { return PSR_ERROR_DATABASE; @@ -841,7 +841,7 @@ PSR_C_API psr_error_t psr_database_update_set_integers(psr_database_t* db, } } -PSR_C_API psr_error_t psr_database_update_set_doubles(psr_database_t* db, +PSR_C_API psr_error_t psr_database_update_set_floats(psr_database_t* db, const char* collection, const char* attribute, int64_t id, @@ -852,7 +852,7 @@ PSR_C_API psr_error_t psr_database_update_set_doubles(psr_database_t* db, } try { std::vector vec(values, values + count); - db->db.update_set_doubles(collection, attribute, id, vec); + db->db.update_set_floats(collection, attribute, id, vec); return PSR_OK; } catch (const std::exception&) { return PSR_ERROR_DATABASE; diff --git a/src/database.cpp b/src/database.cpp index a0d1a5a..6af4bf3 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -779,7 +779,7 @@ std::vector Database::read_scalar_integers(const std::string& collectio return values; } -std::vector Database::read_scalar_doubles(const std::string& collection, const std::string& attribute) { +std::vector Database::read_scalar_floats(const std::string& collection, const std::string& attribute) { auto sql = "SELECT " + attribute + " FROM " + collection; auto result = execute(sql); @@ -821,7 +821,7 @@ Database::read_scalar_integers_by_id(const std::string& collection, const std::s } std::optional -Database::read_scalar_doubles_by_id(const std::string& collection, const std::string& attribute, int64_t id) { +Database::read_scalar_floats_by_id(const std::string& collection, const std::string& attribute, int64_t id) { auto sql = "SELECT " + attribute + " FROM " + collection + " WHERE id = ?"; auto result = execute(sql, {id}); @@ -870,7 +870,7 @@ std::vector> Database::read_vector_integers(const std::stri return vectors; } -std::vector> Database::read_vector_doubles(const std::string& collection, +std::vector> Database::read_vector_floats(const std::string& collection, const std::string& attribute) { auto vector_table = impl_->schema->find_vector_table(collection, attribute); auto sql = "SELECT id, " + attribute + " FROM " + vector_table + " ORDER BY id, vector_index"; @@ -944,7 +944,7 @@ Database::read_vector_integers_by_id(const std::string& collection, const std::s } std::vector -Database::read_vector_doubles_by_id(const std::string& collection, const std::string& attribute, int64_t id) { +Database::read_vector_floats_by_id(const std::string& collection, const std::string& attribute, int64_t id) { auto vector_table = impl_->schema->find_vector_table(collection, attribute); auto sql = "SELECT " + attribute + " FROM " + vector_table + " WHERE id = ? ORDER BY vector_index"; auto result = execute(sql, {id}); @@ -1005,7 +1005,7 @@ std::vector> Database::read_set_integers(const std::string& return sets; } -std::vector> Database::read_set_doubles(const std::string& collection, +std::vector> Database::read_set_floats(const std::string& collection, const std::string& attribute) { auto set_table = impl_->schema->find_set_table(collection, attribute); auto sql = "SELECT id, " + attribute + " FROM " + set_table + " ORDER BY id"; @@ -1079,7 +1079,7 @@ Database::read_set_integers_by_id(const std::string& collection, const std::stri } std::vector -Database::read_set_doubles_by_id(const std::string& collection, const std::string& attribute, int64_t id) { +Database::read_set_floats_by_id(const std::string& collection, const std::string& attribute, int64_t id) { auto set_table = impl_->schema->find_set_table(collection, attribute); auto sql = "SELECT " + attribute + " FROM " + set_table + " WHERE id = ?"; auto result = execute(sql, {id}); @@ -1198,7 +1198,7 @@ void Database::update_vector_integers(const std::string& collection, impl_->logger->info("Updated vector {}.{} for id {} with {} values", collection, attribute, id, values.size()); } -void Database::update_vector_doubles(const std::string& collection, +void Database::update_vector_floats(const std::string& collection, const std::string& attribute, int64_t id, const std::vector& values) { @@ -1284,7 +1284,7 @@ void Database::update_set_integers(const std::string& collection, impl_->logger->info("Updated set {}.{} for id {} with {} values", collection, attribute, id, values.size()); } -void Database::update_set_doubles(const std::string& collection, +void Database::update_set_floats(const std::string& collection, const std::string& attribute, int64_t id, const std::vector& values) { diff --git a/src/lua_runner.cpp b/src/lua_runner.cpp index 34bb552..c5a6c88 100644 --- a/src/lua_runner.cpp +++ b/src/lua_runner.cpp @@ -33,17 +33,17 @@ struct LuaRunner::Impl { [](Database& self, const std::string& collection, const std::string& attribute, sol::this_state s) { return read_scalar_integers_to_lua(self, collection, attribute, s); }, - "read_scalar_doubles", + "read_scalar_floats", [](Database& self, const std::string& collection, const std::string& attribute, sol::this_state s) { - return read_scalar_doubles_to_lua(self, collection, attribute, s); + return read_scalar_floats_to_lua(self, collection, attribute, s); }, "read_vector_integers", [](Database& self, const std::string& collection, const std::string& attribute, sol::this_state s) { return read_vector_integers_to_lua(self, collection, attribute, s); }, - "read_vector_doubles", + "read_vector_floats", [](Database& self, const std::string& collection, const std::string& attribute, sol::this_state s) { - return read_vector_doubles_to_lua(self, collection, attribute, s); + return read_vector_floats_to_lua(self, collection, attribute, s); }, "read_vector_strings", [](Database& self, const std::string& collection, const std::string& attribute, sol::this_state s) { @@ -61,24 +61,24 @@ struct LuaRunner::Impl { const std::string& attribute, int64_t id, sol::this_state s) { return read_scalar_integers_by_id_to_lua(self, collection, attribute, id, s); }, - "read_scalar_doubles_by_id", + "read_scalar_floats_by_id", [](Database& self, const std::string& collection, const std::string& attribute, int64_t id, - sol::this_state s) { return read_scalar_doubles_by_id_to_lua(self, collection, attribute, id, s); }, + sol::this_state s) { return read_scalar_floats_by_id_to_lua(self, collection, attribute, id, s); }, "read_vector_integers_by_id", [](Database& self, const std::string& collection, const std::string& attribute, int64_t id, sol::this_state s) { return read_vector_integers_by_id_to_lua(self, collection, attribute, id, s); }, - "read_vector_doubles_by_id", + "read_vector_floats_by_id", [](Database& self, const std::string& collection, const std::string& attribute, int64_t id, - sol::this_state s) { return read_vector_doubles_by_id_to_lua(self, collection, attribute, id, s); }, + sol::this_state s) { return read_vector_floats_by_id_to_lua(self, collection, attribute, id, s); }, "read_vector_strings_by_id", [](Database& self, const std::string& collection, @@ -91,12 +91,12 @@ struct LuaRunner::Impl { const std::string& attribute, int64_t id, sol::this_state s) { return read_set_integers_by_id_to_lua(self, collection, attribute, id, s); }, - "read_set_doubles_by_id", + "read_set_floats_by_id", [](Database& self, const std::string& collection, const std::string& attribute, int64_t id, - sol::this_state s) { return read_set_doubles_by_id_to_lua(self, collection, attribute, id, s); }, + sol::this_state s) { return read_set_floats_by_id_to_lua(self, collection, attribute, id, s); }, "read_set_strings_by_id", [](Database& self, const std::string& collection, @@ -196,12 +196,12 @@ struct LuaRunner::Impl { return t; } - static sol::table read_scalar_doubles_to_lua(Database& db, + static sol::table read_scalar_floats_to_lua(Database& db, const std::string& collection, const std::string& attribute, sol::this_state s) { sol::state_view lua(s); - auto result = db.read_scalar_doubles(collection, attribute); + auto result = db.read_scalar_floats(collection, attribute); sol::table t = lua.create_table(); for (size_t i = 0; i < result.size(); ++i) { t[i + 1] = result[i]; @@ -226,12 +226,12 @@ struct LuaRunner::Impl { return outer; } - static sol::table read_vector_doubles_to_lua(Database& db, + static sol::table read_vector_floats_to_lua(Database& db, const std::string& collection, const std::string& attribute, sol::this_state s) { sol::state_view lua(s); - auto result = db.read_vector_doubles(collection, attribute); + auto result = db.read_vector_floats(collection, attribute); sol::table outer = lua.create_table(); for (size_t i = 0; i < result.size(); ++i) { sol::table inner = lua.create_table(); @@ -287,13 +287,13 @@ struct LuaRunner::Impl { return sol::make_object(lua, sol::nil); } - static sol::object read_scalar_doubles_by_id_to_lua(Database& db, + static sol::object read_scalar_floats_by_id_to_lua(Database& db, const std::string& collection, const std::string& attribute, int64_t id, sol::this_state s) { sol::state_view lua(s); - auto result = db.read_scalar_doubles_by_id(collection, attribute, id); + auto result = db.read_scalar_floats_by_id(collection, attribute, id); if (result.has_value()) { return sol::make_object(lua, *result); } @@ -315,13 +315,13 @@ struct LuaRunner::Impl { return t; } - static sol::table read_vector_doubles_by_id_to_lua(Database& db, + static sol::table read_vector_floats_by_id_to_lua(Database& db, const std::string& collection, const std::string& attribute, int64_t id, sol::this_state s) { sol::state_view lua(s); - auto result = db.read_vector_doubles_by_id(collection, attribute, id); + auto result = db.read_vector_floats_by_id(collection, attribute, id); sol::table t = lua.create_table(); for (size_t i = 0; i < result.size(); ++i) { t[i + 1] = result[i]; @@ -358,13 +358,13 @@ struct LuaRunner::Impl { return t; } - static sol::table read_set_doubles_by_id_to_lua(Database& db, + static sol::table read_set_floats_by_id_to_lua(Database& db, const std::string& collection, const std::string& attribute, int64_t id, sol::this_state s) { sol::state_view lua(s); - auto result = db.read_set_doubles_by_id(collection, attribute, id); + auto result = db.read_set_floats_by_id(collection, attribute, id); sol::table t = lua.create_table(); for (size_t i = 0; i < result.size(); ++i) { t[i + 1] = result[i]; diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index 3b02eee..f9a08b2 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -42,7 +42,7 @@ TEST(DatabaseCApi, ReadScalarIntegers) { psr_database_close(db); } -TEST(DatabaseCApi, ReadScalarDoubles) { +TEST(DatabaseCApi, ReadScalarFloats) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("basic.sql").c_str(), &options); @@ -62,7 +62,7 @@ TEST(DatabaseCApi, ReadScalarDoubles) { double* values = nullptr; size_t count = 0; - auto err = psr_database_read_scalar_doubles(db, "Configuration", "float_attribute", &values, &count); + auto err = psr_database_read_scalar_floats(db, "Configuration", "float_attribute", &values, &count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(count, 2); @@ -124,7 +124,7 @@ TEST(DatabaseCApi, ReadScalarEmpty) { double* double_values = nullptr; size_t double_count = 0; - err = psr_database_read_scalar_doubles(db, "Collection", "some_float", &double_values, &double_count); + err = psr_database_read_scalar_floats(db, "Collection", "some_float", &double_values, &double_count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(double_count, 0); EXPECT_EQ(double_values, nullptr); @@ -180,7 +180,7 @@ TEST(DatabaseCApi, ReadVectorIntegers) { psr_database_close(db); } -TEST(DatabaseCApi, ReadVectorDoubles) { +TEST(DatabaseCApi, ReadVectorFloats) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("collections.sql").c_str(), &options); @@ -208,7 +208,7 @@ TEST(DatabaseCApi, ReadVectorDoubles) { double** vectors = nullptr; size_t* sizes = nullptr; size_t count = 0; - auto err = psr_database_read_vector_doubles(db, "Collection", "value_float", &vectors, &sizes, &count); + auto err = psr_database_read_vector_floats(db, "Collection", "value_float", &vectors, &sizes, &count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(count, 2); @@ -247,7 +247,7 @@ TEST(DatabaseCApi, ReadVectorEmpty) { double** double_vectors = nullptr; size_t* double_sizes = nullptr; size_t double_count = 0; - err = psr_database_read_vector_doubles( + err = psr_database_read_vector_floats( db, "Collection", "value_float", &double_vectors, &double_sizes, &double_count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(double_count, 0); @@ -489,7 +489,7 @@ TEST(DatabaseCApi, ReadScalarDoubleById) { double value; int has_value; - auto err = psr_database_read_scalar_doubles_by_id(db, "Configuration", "float_attribute", id1, &value, &has_value); + auto err = psr_database_read_scalar_floats_by_id(db, "Configuration", "float_attribute", id1, &value, &has_value); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(has_value, 1); @@ -615,7 +615,7 @@ TEST(DatabaseCApi, ReadVectorDoubleById) { double* values = nullptr; size_t count = 0; - auto err = psr_database_read_vector_doubles_by_id(db, "Collection", "value_float", id1, &values, &count); + auto err = psr_database_read_vector_floats_by_id(db, "Collection", "value_float", id1, &values, &count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(count, 3); @@ -1008,14 +1008,14 @@ TEST(DatabaseCApi, ReadScalarIntegersNullOutput) { psr_database_close(db); } -TEST(DatabaseCApi, ReadScalarDoublesNullDb) { +TEST(DatabaseCApi, ReadScalarFloatsNullDb) { double* values = nullptr; size_t count = 0; - auto err = psr_database_read_scalar_doubles(nullptr, "Configuration", "float_attribute", &values, &count); + auto err = psr_database_read_scalar_floats(nullptr, "Configuration", "float_attribute", &values, &count); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); } -TEST(DatabaseCApi, ReadScalarDoublesNullCollection) { +TEST(DatabaseCApi, ReadScalarFloatsNullCollection) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("basic.sql").c_str(), &options); @@ -1023,24 +1023,24 @@ TEST(DatabaseCApi, ReadScalarDoublesNullCollection) { double* values = nullptr; size_t count = 0; - auto err = psr_database_read_scalar_doubles(db, nullptr, "float_attribute", &values, &count); + auto err = psr_database_read_scalar_floats(db, nullptr, "float_attribute", &values, &count); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); psr_database_close(db); } -TEST(DatabaseCApi, ReadScalarDoublesNullOutput) { +TEST(DatabaseCApi, ReadScalarFloatsNullOutput) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("basic.sql").c_str(), &options); ASSERT_NE(db, nullptr); size_t count = 0; - auto err = psr_database_read_scalar_doubles(db, "Configuration", "float_attribute", nullptr, &count); + auto err = psr_database_read_scalar_floats(db, "Configuration", "float_attribute", nullptr, &count); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); double* values = nullptr; - err = psr_database_read_scalar_doubles(db, "Configuration", "float_attribute", &values, nullptr); + err = psr_database_read_scalar_floats(db, "Configuration", "float_attribute", &values, nullptr); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); psr_database_close(db); @@ -1128,26 +1128,26 @@ TEST(DatabaseCApi, ReadScalarIntegersByIdNullOutput) { psr_database_close(db); } -TEST(DatabaseCApi, ReadScalarDoublesByIdNullDb) { +TEST(DatabaseCApi, ReadScalarFloatsByIdNullDb) { double value; int has_value; auto err = - psr_database_read_scalar_doubles_by_id(nullptr, "Configuration", "float_attribute", 1, &value, &has_value); + psr_database_read_scalar_floats_by_id(nullptr, "Configuration", "float_attribute", 1, &value, &has_value); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); } -TEST(DatabaseCApi, ReadScalarDoublesByIdNullOutput) { +TEST(DatabaseCApi, ReadScalarFloatsByIdNullOutput) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("basic.sql").c_str(), &options); ASSERT_NE(db, nullptr); int has_value; - auto err = psr_database_read_scalar_doubles_by_id(db, "Configuration", "float_attribute", 1, nullptr, &has_value); + auto err = psr_database_read_scalar_floats_by_id(db, "Configuration", "float_attribute", 1, nullptr, &has_value); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); double value; - err = psr_database_read_scalar_doubles_by_id(db, "Configuration", "float_attribute", 1, &value, nullptr); + err = psr_database_read_scalar_floats_by_id(db, "Configuration", "float_attribute", 1, &value, nullptr); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); psr_database_close(db); @@ -1226,15 +1226,15 @@ TEST(DatabaseCApi, ReadVectorIntegersNullOutput) { psr_database_close(db); } -TEST(DatabaseCApi, ReadVectorDoublesNullDb) { +TEST(DatabaseCApi, ReadVectorFloatsNullDb) { double** vectors = nullptr; size_t* sizes = nullptr; size_t count = 0; - auto err = psr_database_read_vector_doubles(nullptr, "Collection", "value_float", &vectors, &sizes, &count); + auto err = psr_database_read_vector_floats(nullptr, "Collection", "value_float", &vectors, &sizes, &count); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); } -TEST(DatabaseCApi, ReadVectorDoublesNullOutput) { +TEST(DatabaseCApi, ReadVectorFloatsNullOutput) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("collections.sql").c_str(), &options); @@ -1242,14 +1242,14 @@ TEST(DatabaseCApi, ReadVectorDoublesNullOutput) { size_t* sizes = nullptr; size_t count = 0; - auto err = psr_database_read_vector_doubles(db, "Collection", "value_float", nullptr, &sizes, &count); + auto err = psr_database_read_vector_floats(db, "Collection", "value_float", nullptr, &sizes, &count); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); double** vectors = nullptr; - err = psr_database_read_vector_doubles(db, "Collection", "value_float", &vectors, nullptr, &count); + err = psr_database_read_vector_floats(db, "Collection", "value_float", &vectors, nullptr, &count); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); - err = psr_database_read_vector_doubles(db, "Collection", "value_float", &vectors, &sizes, nullptr); + err = psr_database_read_vector_floats(db, "Collection", "value_float", &vectors, &sizes, nullptr); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); psr_database_close(db); @@ -1305,25 +1305,25 @@ TEST(DatabaseCApi, ReadVectorIntegersByIdNullOutput) { psr_database_close(db); } -TEST(DatabaseCApi, ReadVectorDoublesByIdNullDb) { +TEST(DatabaseCApi, ReadVectorFloatsByIdNullDb) { double* values = nullptr; size_t count = 0; - auto err = psr_database_read_vector_doubles_by_id(nullptr, "Collection", "value_float", 1, &values, &count); + auto err = psr_database_read_vector_floats_by_id(nullptr, "Collection", "value_float", 1, &values, &count); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); } -TEST(DatabaseCApi, ReadVectorDoublesByIdNullOutput) { +TEST(DatabaseCApi, ReadVectorFloatsByIdNullOutput) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("collections.sql").c_str(), &options); ASSERT_NE(db, nullptr); size_t count = 0; - auto err = psr_database_read_vector_doubles_by_id(db, "Collection", "value_float", 1, nullptr, &count); + auto err = psr_database_read_vector_floats_by_id(db, "Collection", "value_float", 1, nullptr, &count); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); double* values = nullptr; - err = psr_database_read_vector_doubles_by_id(db, "Collection", "value_float", 1, &values, nullptr); + err = psr_database_read_vector_floats_by_id(db, "Collection", "value_float", 1, &values, nullptr); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); psr_database_close(db); @@ -1384,11 +1384,11 @@ TEST(DatabaseCApi, ReadSetIntegersNullOutput) { psr_database_close(db); } -TEST(DatabaseCApi, ReadSetDoublesNullDb) { +TEST(DatabaseCApi, ReadSetFloatsNullDb) { double** sets = nullptr; size_t* sizes = nullptr; size_t count = 0; - auto err = psr_database_read_set_doubles(nullptr, "Collection", "tag", &sets, &sizes, &count); + auto err = psr_database_read_set_floats(nullptr, "Collection", "tag", &sets, &sizes, &count); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); } @@ -1447,10 +1447,10 @@ TEST(DatabaseCApi, ReadSetIntegersByIdNullDb) { EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); } -TEST(DatabaseCApi, ReadSetDoublesByIdNullDb) { +TEST(DatabaseCApi, ReadSetFloatsByIdNullDb) { double* values = nullptr; size_t count = 0; - auto err = psr_database_read_set_doubles_by_id(nullptr, "Collection", "tag", 1, &values, &count); + auto err = psr_database_read_set_floats_by_id(nullptr, "Collection", "tag", 1, &values, &count); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); } diff --git a/tests/test_c_api_database_update.cpp b/tests/test_c_api_database_update.cpp index 09c6173..5bd39c2 100644 --- a/tests/test_c_api_database_update.cpp +++ b/tests/test_c_api_database_update.cpp @@ -53,7 +53,7 @@ TEST(DatabaseCApi, UpdateScalarDouble) { double value; int has_value; - err = psr_database_read_scalar_doubles_by_id(db, "Configuration", "float_attribute", id, &value, &has_value); + err = psr_database_read_scalar_floats_by_id(db, "Configuration", "float_attribute", id, &value, &has_value); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(has_value, 1); EXPECT_DOUBLE_EQ(value, 2.71); @@ -127,7 +127,7 @@ TEST(DatabaseCApi, UpdateVectorIntegers) { psr_database_close(db); } -TEST(DatabaseCApi, UpdateVectorDoubles) { +TEST(DatabaseCApi, UpdateVectorFloats) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("collections.sql").c_str(), &options); @@ -146,12 +146,12 @@ TEST(DatabaseCApi, UpdateVectorDoubles) { psr_element_destroy(e); double new_values[] = {10.5, 20.5}; - auto err = psr_database_update_vector_doubles(db, "Collection", "value_float", id, new_values, 2); + auto err = psr_database_update_vector_floats(db, "Collection", "value_float", id, new_values, 2); EXPECT_EQ(err, PSR_OK); double* read_values = nullptr; size_t count = 0; - err = psr_database_read_vector_doubles_by_id(db, "Collection", "value_float", id, &read_values, &count); + err = psr_database_read_vector_floats_by_id(db, "Collection", "value_float", id, &read_values, &count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(count, 2); EXPECT_DOUBLE_EQ(read_values[0], 10.5); @@ -340,7 +340,7 @@ TEST(DatabaseCApi, UpdateElementMultipleScalars) { EXPECT_EQ(int_value, 100); double double_value; - err = psr_database_read_scalar_doubles_by_id(db, "Configuration", "float_attribute", id, &double_value, &has_value); + err = psr_database_read_scalar_floats_by_id(db, "Configuration", "float_attribute", id, &double_value, &has_value); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(has_value, 1); EXPECT_DOUBLE_EQ(double_value, 2.71); @@ -546,20 +546,20 @@ TEST(DatabaseCApi, UpdateVectorIntegersNullAttribute) { psr_database_close(db); } -TEST(DatabaseCApi, UpdateVectorDoublesNullDb) { +TEST(DatabaseCApi, UpdateVectorFloatsNullDb) { double values[] = {1.0, 2.0, 3.0}; - auto err = psr_database_update_vector_doubles(nullptr, "Collection", "value_float", 1, values, 3); + auto err = psr_database_update_vector_floats(nullptr, "Collection", "value_float", 1, values, 3); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); } -TEST(DatabaseCApi, UpdateVectorDoublesNullCollection) { +TEST(DatabaseCApi, UpdateVectorFloatsNullCollection) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("collections.sql").c_str(), &options); ASSERT_NE(db, nullptr); double values[] = {1.0, 2.0, 3.0}; - auto err = psr_database_update_vector_doubles(db, nullptr, "value_float", 1, values, 3); + auto err = psr_database_update_vector_floats(db, nullptr, "value_float", 1, values, 3); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); psr_database_close(db); @@ -607,20 +607,20 @@ TEST(DatabaseCApi, UpdateSetIntegersNullCollection) { psr_database_close(db); } -TEST(DatabaseCApi, UpdateSetDoublesNullDb) { +TEST(DatabaseCApi, UpdateSetFloatsNullDb) { double values[] = {1.0, 2.0, 3.0}; - auto err = psr_database_update_set_doubles(nullptr, "Collection", "tag", 1, values, 3); + auto err = psr_database_update_set_floats(nullptr, "Collection", "tag", 1, values, 3); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); } -TEST(DatabaseCApi, UpdateSetDoublesNullCollection) { +TEST(DatabaseCApi, UpdateSetFloatsNullCollection) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("collections.sql").c_str(), &options); ASSERT_NE(db, nullptr); double values[] = {1.0, 2.0, 3.0}; - auto err = psr_database_update_set_doubles(db, nullptr, "tag", 1, values, 3); + auto err = psr_database_update_set_floats(db, nullptr, "tag", 1, values, 3); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); psr_database_close(db); diff --git a/tests/test_database_create.cpp b/tests/test_database_create.cpp index 94667d7..3e01111 100644 --- a/tests/test_database_create.cpp +++ b/tests/test_database_create.cpp @@ -17,7 +17,7 @@ TEST(Database, CreateElementWithScalars) { // Verify using public read APIs auto labels = db.read_scalar_strings("Configuration", "label"); auto integers = db.read_scalar_integers("Configuration", "integer_attribute"); - auto floats = db.read_scalar_doubles("Configuration", "float_attribute"); + auto floats = db.read_scalar_floats("Configuration", "float_attribute"); EXPECT_EQ(labels.size(), 1); EXPECT_EQ(labels[0], "Config 1"); @@ -52,7 +52,7 @@ TEST(Database, CreateElementWithVector) { EXPECT_EQ(int_vectors.size(), 1); EXPECT_EQ(int_vectors[0], (std::vector{1, 2, 3})); - auto float_vectors = db.read_vector_doubles("Collection", "value_float"); + auto float_vectors = db.read_vector_floats("Collection", "value_float"); EXPECT_EQ(float_vectors.size(), 1); EXPECT_EQ(float_vectors[0], (std::vector{1.5, 2.5, 3.5})); } @@ -80,7 +80,7 @@ TEST(Database, CreateElementWithVectorGroup) { EXPECT_EQ(int_vectors.size(), 1); EXPECT_EQ(int_vectors[0], (std::vector{10, 20, 30})); - auto float_vectors = db.read_vector_doubles("Collection", "value_float"); + auto float_vectors = db.read_vector_floats("Collection", "value_float"); EXPECT_EQ(float_vectors.size(), 1); EXPECT_EQ(float_vectors[0], (std::vector{1.5, 2.5, 3.5})); } diff --git a/tests/test_database_errors.cpp b/tests/test_database_errors.cpp index 05b402d..5d0dc0c 100644 --- a/tests/test_database_errors.cpp +++ b/tests/test_database_errors.cpp @@ -113,10 +113,10 @@ TEST(DatabaseErrors, ReadScalarIntegersNoSchema) { EXPECT_THROW(db.read_scalar_integers("Configuration", "integer_attribute"), std::runtime_error); } -TEST(DatabaseErrors, ReadScalarDoublesNoSchema) { +TEST(DatabaseErrors, ReadScalarFloatsNoSchema) { psr::Database db(":memory:", {.console_level = psr::LogLevel::off}); - EXPECT_THROW(db.read_scalar_doubles("Configuration", "float_attribute"), std::runtime_error); + EXPECT_THROW(db.read_scalar_floats("Configuration", "float_attribute"), std::runtime_error); } TEST(DatabaseErrors, ReadScalarStringsNoSchema) { @@ -144,7 +144,7 @@ TEST(DatabaseErrors, ReadVectorIntegersCollectionNotFound) { EXPECT_THROW(db.read_vector_integers("NonexistentCollection", "value_int"), std::exception); } -TEST(DatabaseErrors, ReadVectorDoublesCollectionNotFound) { +TEST(DatabaseErrors, ReadVectorFloatsCollectionNotFound) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); @@ -152,7 +152,7 @@ TEST(DatabaseErrors, ReadVectorDoublesCollectionNotFound) { config.set("label", std::string("Config")); db.create_element("Configuration", config); - EXPECT_THROW(db.read_vector_doubles("NonexistentCollection", "value_float"), std::exception); + EXPECT_THROW(db.read_vector_floats("NonexistentCollection", "value_float"), std::exception); } // ============================================================================ @@ -295,7 +295,7 @@ TEST(DatabaseErrors, UpdateVectorIntegersCollectionNotFound) { EXPECT_THROW(db.update_vector_integers("NonexistentCollection", "value_int", 1, {1, 2, 3}), std::exception); } -TEST(DatabaseErrors, UpdateVectorDoublesCollectionNotFound) { +TEST(DatabaseErrors, UpdateVectorFloatsCollectionNotFound) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); @@ -303,7 +303,7 @@ TEST(DatabaseErrors, UpdateVectorDoublesCollectionNotFound) { config.set("label", std::string("Config")); db.create_element("Configuration", config); - EXPECT_THROW(db.update_vector_doubles("NonexistentCollection", "value_float", 1, {1.5, 2.5}), std::exception); + EXPECT_THROW(db.update_vector_floats("NonexistentCollection", "value_float", 1, {1.5, 2.5}), std::exception); } // ============================================================================ @@ -339,14 +339,14 @@ TEST(DatabaseErrors, ReadScalarIntegersAttributeNotFound) { EXPECT_THROW(db.read_scalar_integers("Configuration", "nonexistent_attribute"), std::runtime_error); } -TEST(DatabaseErrors, ReadScalarDoublesAttributeNotFound) { +TEST(DatabaseErrors, ReadScalarFloatsAttributeNotFound) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("basic.sql"), {.console_level = psr::LogLevel::off}); psr::Element e; e.set("label", std::string("Test")); db.create_element("Configuration", e); - EXPECT_THROW(db.read_scalar_doubles("Configuration", "nonexistent_attribute"), std::runtime_error); + EXPECT_THROW(db.read_scalar_floats("Configuration", "nonexistent_attribute"), std::runtime_error); } TEST(DatabaseErrors, ReadScalarStringsAttributeNotFound) { @@ -374,7 +374,7 @@ TEST(DatabaseErrors, ReadVectorIntegersAttributeNotFound) { EXPECT_THROW(db.read_vector_integers("Collection", "nonexistent_attribute"), std::exception); } -TEST(DatabaseErrors, ReadVectorDoublesAttributeNotFound) { +TEST(DatabaseErrors, ReadVectorFloatsAttributeNotFound) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); @@ -382,7 +382,7 @@ TEST(DatabaseErrors, ReadVectorDoublesAttributeNotFound) { config.set("label", std::string("Config")); db.create_element("Configuration", config); - EXPECT_THROW(db.read_vector_doubles("Collection", "nonexistent_attribute"), std::exception); + EXPECT_THROW(db.read_vector_floats("Collection", "nonexistent_attribute"), std::exception); } TEST(DatabaseErrors, ReadVectorStringsAttributeNotFound) { @@ -411,7 +411,7 @@ TEST(DatabaseErrors, ReadSetIntegersAttributeNotFound) { EXPECT_THROW(db.read_set_integers("Collection", "nonexistent_attribute"), std::exception); } -TEST(DatabaseErrors, ReadSetDoublesAttributeNotFound) { +TEST(DatabaseErrors, ReadSetFloatsAttributeNotFound) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); @@ -419,7 +419,7 @@ TEST(DatabaseErrors, ReadSetDoublesAttributeNotFound) { config.set("label", std::string("Config")); db.create_element("Configuration", config); - EXPECT_THROW(db.read_set_doubles("Collection", "nonexistent_attribute"), std::exception); + EXPECT_THROW(db.read_set_floats("Collection", "nonexistent_attribute"), std::exception); } // ============================================================================ diff --git a/tests/test_database_read.cpp b/tests/test_database_read.cpp index d84b4e1..c7c9cea 100644 --- a/tests/test_database_read.cpp +++ b/tests/test_database_read.cpp @@ -26,7 +26,7 @@ TEST(Database, ReadScalarIntegers) { EXPECT_EQ(values[1], 100); } -TEST(Database, ReadScalarDoubles) { +TEST(Database, ReadScalarFloats) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("basic.sql"), {.console_level = psr::LogLevel::off}); psr::Element e1; @@ -37,7 +37,7 @@ TEST(Database, ReadScalarDoubles) { e2.set("label", std::string("Config 2")).set("float_attribute", 2.71); db.create_element("Configuration", e2); - auto values = db.read_scalar_doubles("Configuration", "float_attribute"); + auto values = db.read_scalar_floats("Configuration", "float_attribute"); EXPECT_EQ(values.size(), 2); EXPECT_DOUBLE_EQ(values[0], 3.14); EXPECT_DOUBLE_EQ(values[1], 2.71); @@ -70,11 +70,11 @@ TEST(Database, ReadScalarEmpty) { // No Collection elements created auto integers = db.read_scalar_integers("Collection", "some_integer"); - auto doubles = db.read_scalar_doubles("Collection", "some_float"); + auto floats = db.read_scalar_floats("Collection", "some_float"); auto strings = db.read_scalar_strings("Collection", "label"); EXPECT_TRUE(integers.empty()); - EXPECT_TRUE(doubles.empty()); + EXPECT_TRUE(floats.empty()); EXPECT_TRUE(strings.empty()); } @@ -104,7 +104,7 @@ TEST(Database, ReadVectorIntegers) { EXPECT_EQ(vectors[1], (std::vector{10, 20})); } -TEST(Database, ReadVectorDoubles) { +TEST(Database, ReadVectorFloats) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); @@ -120,7 +120,7 @@ TEST(Database, ReadVectorDoubles) { e2.set("label", std::string("Item 2")).set("value_float", std::vector{10.5, 20.5}); db.create_element("Collection", e2); - auto vectors = db.read_vector_doubles("Collection", "value_float"); + auto vectors = db.read_vector_floats("Collection", "value_float"); EXPECT_EQ(vectors.size(), 2); EXPECT_EQ(vectors[0], (std::vector{1.5, 2.5, 3.5})); EXPECT_EQ(vectors[1], (std::vector{10.5, 20.5})); @@ -136,7 +136,7 @@ TEST(Database, ReadVectorEmpty) { // No Collection elements created auto int_vectors = db.read_vector_integers("Collection", "value_int"); - auto double_vectors = db.read_vector_doubles("Collection", "value_float"); + auto double_vectors = db.read_vector_floats("Collection", "value_float"); EXPECT_TRUE(int_vectors.empty()); EXPECT_TRUE(double_vectors.empty()); @@ -279,8 +279,8 @@ TEST(Database, ReadScalarDoubleById) { e2.set("label", std::string("Config 2")).set("float_attribute", 2.71); int64_t id2 = db.create_element("Configuration", e2); - auto val1 = db.read_scalar_doubles_by_id("Configuration", "float_attribute", id1); - auto val2 = db.read_scalar_doubles_by_id("Configuration", "float_attribute", id2); + auto val1 = db.read_scalar_floats_by_id("Configuration", "float_attribute", id1); + auto val2 = db.read_scalar_floats_by_id("Configuration", "float_attribute", id2); EXPECT_TRUE(val1.has_value()); EXPECT_DOUBLE_EQ(*val1, 3.14); @@ -363,8 +363,8 @@ TEST(Database, ReadVectorDoubleById) { e2.set("label", std::string("Item 2")).set("value_float", std::vector{10.5, 20.5}); int64_t id2 = db.create_element("Collection", e2); - auto vec1 = db.read_vector_doubles_by_id("Collection", "value_float", id1); - auto vec2 = db.read_vector_doubles_by_id("Collection", "value_float", id2); + auto vec1 = db.read_vector_floats_by_id("Collection", "value_float", id1); + auto vec2 = db.read_vector_floats_by_id("Collection", "value_float", id2); EXPECT_EQ(vec1, (std::vector{1.5, 2.5, 3.5})); EXPECT_EQ(vec2, (std::vector{10.5, 20.5})); @@ -553,10 +553,10 @@ TEST(Database, ReadScalarIntegersInvalidAttribute) { EXPECT_THROW(db.read_scalar_integers("Configuration", "nonexistent_attribute"), std::runtime_error); } -TEST(Database, ReadScalarDoublesInvalidCollection) { +TEST(Database, ReadScalarFloatsInvalidCollection) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("basic.sql"), {.console_level = psr::LogLevel::off}); - EXPECT_THROW(db.read_scalar_doubles("NonexistentCollection", "float_attribute"), std::runtime_error); + EXPECT_THROW(db.read_scalar_floats("NonexistentCollection", "float_attribute"), std::runtime_error); } TEST(Database, ReadScalarStringsInvalidCollection) { diff --git a/tests/test_database_update.cpp b/tests/test_database_update.cpp index a64b437..0d10455 100644 --- a/tests/test_database_update.cpp +++ b/tests/test_database_update.cpp @@ -31,7 +31,7 @@ TEST(Database, UpdateScalarDouble) { db.update_scalar_double("Configuration", "float_attribute", id, 2.71); - auto val = db.read_scalar_doubles_by_id("Configuration", "float_attribute", id); + auto val = db.read_scalar_floats_by_id("Configuration", "float_attribute", id); EXPECT_TRUE(val.has_value()); EXPECT_DOUBLE_EQ(*val, 2.71); } @@ -97,7 +97,7 @@ TEST(Database, UpdateVectorIntegers) { EXPECT_EQ(vec, (std::vector{10, 20, 30, 40})); } -TEST(Database, UpdateVectorDoubles) { +TEST(Database, UpdateVectorFloats) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); @@ -109,9 +109,9 @@ TEST(Database, UpdateVectorDoubles) { e.set("label", std::string("Item 1")).set("value_float", std::vector{1.5, 2.5, 3.5}); int64_t id = db.create_element("Collection", e); - db.update_vector_doubles("Collection", "value_float", id, {10.5, 20.5}); + db.update_vector_floats("Collection", "value_float", id, {10.5, 20.5}); - auto vec = db.read_vector_doubles_by_id("Collection", "value_float", id); + auto vec = db.read_vector_floats_by_id("Collection", "value_float", id); EXPECT_EQ(vec, (std::vector{10.5, 20.5})); } @@ -278,7 +278,7 @@ TEST(Database, UpdateElementMultipleScalars) { EXPECT_TRUE(int_val.has_value()); EXPECT_EQ(*int_val, 100); - auto float_val = db.read_scalar_doubles_by_id("Configuration", "float_attribute", id); + auto float_val = db.read_scalar_floats_by_id("Configuration", "float_attribute", id); EXPECT_TRUE(float_val.has_value()); EXPECT_DOUBLE_EQ(*float_val, 2.71); diff --git a/tests/test_lua_runner.cpp b/tests/test_lua_runner.cpp index 3f4c7c9..a8c5084 100644 --- a/tests/test_lua_runner.cpp +++ b/tests/test_lua_runner.cpp @@ -73,7 +73,7 @@ TEST_F(LuaRunnerTest, CreateElementWithArrays) { EXPECT_EQ(vectors.size(), 1); EXPECT_EQ(vectors[0], (std::vector{1, 2, 3})); - auto floats = db.read_vector_doubles("Collection", "value_float"); + auto floats = db.read_vector_floats("Collection", "value_float"); EXPECT_EQ(floats.size(), 1); EXPECT_EQ(floats[0], (std::vector{1.5, 2.5, 3.5})); } @@ -116,7 +116,7 @@ TEST_F(LuaRunnerTest, ReadScalarIntegersFromLua) { )"); } -TEST_F(LuaRunnerTest, ReadScalarDoublesFromLua) { +TEST_F(LuaRunnerTest, ReadScalarFloatsFromLua) { auto db = psr::Database::from_schema(":memory:", collections_schema); db.create_element("Configuration", psr::Element().set("label", "Config")); @@ -126,10 +126,10 @@ TEST_F(LuaRunnerTest, ReadScalarDoublesFromLua) { psr::LuaRunner lua(db); lua.run(R"( - local doubles = db:read_scalar_doubles("Collection", "some_float") - assert(#doubles == 2, "Expected 2 doubles") - assert(doubles[1] == 1.5, "First double should be 1.5") - assert(doubles[2] == 2.5, "Second double should be 2.5") + local floats = db:read_scalar_floats("Collection", "some_float") + assert(#floats == 2, "Expected 2 floats") + assert(floats[1] == 1.5, "First double should be 1.5") + assert(floats[2] == 2.5, "Second double should be 2.5") )"); } @@ -161,7 +161,7 @@ TEST_F(LuaRunnerTest, ReadVectorIntegersFromLua) { )"); } -TEST_F(LuaRunnerTest, ReadVectorDoublesFromLua) { +TEST_F(LuaRunnerTest, ReadVectorFloatsFromLua) { auto db = psr::Database::from_schema(":memory:", collections_schema); db.create_element("Configuration", psr::Element().set("label", "Config")); @@ -171,7 +171,7 @@ TEST_F(LuaRunnerTest, ReadVectorDoublesFromLua) { psr::LuaRunner lua(db); lua.run(R"( - local vectors = db:read_vector_doubles("Collection", "value_float") + local vectors = db:read_vector_floats("Collection", "value_float") assert(#vectors == 1, "Expected 1 vector") assert(#vectors[1] == 3, "Vector should have 3 elements") assert(vectors[1][1] == 1.1, "vector[1] should be 1.1") @@ -287,7 +287,7 @@ TEST_F(LuaRunnerTest, ReadScalarDoubleByIdFromLua) { psr::LuaRunner lua(db); std::string script = R"( - local val1 = db:read_scalar_doubles_by_id("Collection", "some_float", )" + + local val1 = db:read_scalar_floats_by_id("Collection", "some_float", )" + std::to_string(id1) + R"() assert(val1 == 3.14, "Expected 3.14, got " .. tostring(val1)) )"; @@ -563,7 +563,7 @@ TEST_F(LuaRunnerTest, UpdateElementMultipleScalarsFromLua) { local int_val = db:read_scalar_integers_by_id("Collection", "some_integer", 1) assert(int_val == 500, "Expected integer 500, got " .. tostring(int_val)) - local float_val = db:read_scalar_doubles_by_id("Collection", "some_float", 1) + local float_val = db:read_scalar_floats_by_id("Collection", "some_float", 1) assert(float_val == 9.9, "Expected float 9.9, got " .. tostring(float_val)) -- Verify label unchanged @@ -576,7 +576,7 @@ TEST_F(LuaRunnerTest, UpdateElementMultipleScalarsFromLua) { EXPECT_TRUE(int_value.has_value()); EXPECT_EQ(*int_value, 500); - auto float_value = db.read_scalar_doubles_by_id("Collection", "some_float", 1); + auto float_value = db.read_scalar_floats_by_id("Collection", "some_float", 1); EXPECT_TRUE(float_value.has_value()); EXPECT_DOUBLE_EQ(*float_value, 9.9); } @@ -832,9 +832,9 @@ TEST_F(LuaRunnerTest, CreateElementMixedTypes) { EXPECT_EQ(integers.size(), 1); EXPECT_EQ(integers[0], 42); - auto doubles = db.read_scalar_doubles("Collection", "some_float"); - EXPECT_EQ(doubles.size(), 1); - EXPECT_DOUBLE_EQ(doubles[0], 3.14); + auto floats = db.read_scalar_floats("Collection", "some_float"); + EXPECT_EQ(floats.size(), 1); + EXPECT_DOUBLE_EQ(floats[0], 3.14); } TEST_F(LuaRunnerTest, ReadVectorIntegersByIdFromLua) { @@ -857,7 +857,7 @@ TEST_F(LuaRunnerTest, ReadVectorIntegersByIdFromLua) { lua.run(script); } -TEST_F(LuaRunnerTest, ReadVectorDoublesByIdFromLua) { +TEST_F(LuaRunnerTest, ReadVectorFloatsByIdFromLua) { auto db = psr::Database::from_schema(":memory:", collections_schema); db.create_element("Configuration", psr::Element().set("label", "Config")); @@ -867,7 +867,7 @@ TEST_F(LuaRunnerTest, ReadVectorDoublesByIdFromLua) { psr::LuaRunner lua(db); std::string script = R"( - local vec = db:read_vector_doubles_by_id("Collection", "value_float", )" + + local vec = db:read_vector_floats_by_id("Collection", "value_float", )" + std::to_string(id1) + R"() assert(#vec == 3, "Expected 3 elements, got " .. #vec) assert(vec[1] == 1.1, "First element should be 1.1") diff --git a/tests/test_row_result.cpp b/tests/test_row_result.cpp index a24f93a..1e19526 100644 --- a/tests/test_row_result.cpp +++ b/tests/test_row_result.cpp @@ -275,7 +275,7 @@ TEST(RowResult, ReadScalarByIdWithNull) { // Read optional float attribute (should be nullopt since we didn't set it) // Note: integer_attribute has DEFAULT 6, so we use float_attribute instead - auto result = db.read_scalar_doubles_by_id("Configuration", "float_attribute", id); + auto result = db.read_scalar_floats_by_id("Configuration", "float_attribute", id); EXPECT_FALSE(result.has_value()); } diff --git a/tests/test_schema_validator.cpp b/tests/test_schema_validator.cpp index 5d02dcf..f120088 100644 --- a/tests/test_schema_validator.cpp +++ b/tests/test_schema_validator.cpp @@ -255,7 +255,7 @@ TEST_F(SchemaValidatorFixture, CreateElementWithNullableColumn) { e.set("label", std::string("Test")).set_null("float_attribute"); int64_t id = db.create_element("Configuration", e); - auto val = db.read_scalar_doubles_by_id("Configuration", "float_attribute", id); + auto val = db.read_scalar_floats_by_id("Configuration", "float_attribute", id); EXPECT_FALSE(val.has_value()); // NULL } From 875cc9568eac87db9436e6dfbd4061dbc594f4d7 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:00:13 -0300 Subject: [PATCH 09/32] update --- bindings/dart/lib/src/database.dart | 24 ++++++++++++------------ bindings/dart/lib/src/element.dart | 22 +++++++++++----------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/bindings/dart/lib/src/database.dart b/bindings/dart/lib/src/database.dart index aee5d27..b6b76e0 100644 --- a/bindings/dart/lib/src/database.dart +++ b/bindings/dart/lib/src/database.dart @@ -186,7 +186,7 @@ class Database { } } - /// Reads all double values for a scalar attribute from a collection. + /// Reads all float values for a scalar attribute from a collection. List readScalarFloats(String collection, String attribute) { _ensureNotClosed(); @@ -213,7 +213,7 @@ class Database { } final result = List.generate(count, (i) => outValues.value[i]); - bindings.psr_free_double_array(outValues.value); + bindings.psr_free_float_array(outValues.value); return result; } finally { arena.releaseAll(); @@ -298,7 +298,7 @@ class Database { } } - /// Reads all double vectors for a vector attribute from a collection. + /// Reads all float vectors for a vector attribute from a collection. List> readVectorFloats(String collection, String attribute) { _ensureNotClosed(); @@ -335,7 +335,7 @@ class Database { result.add(List.generate(size, (j) => outVectors.value[i][j])); } } - bindings.psr_free_double_vectors(outVectors.value, outSizes.value, count); + bindings.psr_free_float_vectors(outVectors.value, outSizes.value, count); return result; } finally { arena.releaseAll(); @@ -430,7 +430,7 @@ class Database { } } - /// Reads all double sets for a set attribute from a collection. + /// Reads all float sets for a set attribute from a collection. List> readSetFloats(String collection, String attribute) { _ensureNotClosed(); @@ -467,7 +467,7 @@ class Database { result.add(List.generate(size, (j) => outSets.value[i][j])); } } - bindings.psr_free_double_vectors(outSets.value, outSizes.value, count); + bindings.psr_free_float_vectors(outSets.value, outSizes.value, count); return result; } finally { arena.releaseAll(); @@ -552,9 +552,9 @@ class Database { } } - /// Reads a double value for a scalar attribute by element ID. + /// Reads a float value for a scalar attribute by element ID. /// Returns null if the element is not found. - double? readScalarDoubleById(String collection, String attribute, int id) { + double? readScalarFloatById(String collection, String attribute, int id) { _ensureNotClosed(); final arena = Arena(); @@ -683,7 +683,7 @@ class Database { } final result = List.generate(count, (i) => outValues.value[i]); - bindings.psr_free_double_array(outValues.value); + bindings.psr_free_float_array(outValues.value); return result; } finally { arena.releaseAll(); @@ -790,7 +790,7 @@ class Database { } final result = List.generate(count, (i) => outValues.value[i]); - bindings.psr_free_double_array(outValues.value); + bindings.psr_free_float_array(outValues.value); return result; } finally { arena.releaseAll(); @@ -989,12 +989,12 @@ class Database { } /// Updates a double scalar attribute value by element ID. - void updateScalarDouble(String collection, String attribute, int id, double value) { + void updateScalarFloat(String collection, String attribute, int id, double value) { _ensureNotClosed(); final arena = Arena(); try { - final err = bindings.psr_database_update_scalar_double( + final err = bindings.psr_database_update_scalar_float( _ptr, collection.toNativeUtf8(allocator: arena).cast(), attribute.toNativeUtf8(allocator: arena).cast(), diff --git a/bindings/dart/lib/src/element.dart b/bindings/dart/lib/src/element.dart index 84583aa..ebd7ebd 100644 --- a/bindings/dart/lib/src/element.dart +++ b/bindings/dart/lib/src/element.dart @@ -52,13 +52,13 @@ class Element { case int v: setInteger(name, v); case double v: - setDouble(name, v); + setFloat(name, v); case String v: setString(name, v); case List v: setArrayInteger(name, v); case List v: - setArrayDouble(name, v); + setArrayFloat(name, v); case List v: setArrayString(name, v); case List v when v.isEmpty: @@ -77,7 +77,7 @@ class Element { if (first is int) { setArrayInteger(name, values.cast()); } else if (first is double) { - setArrayDouble(name, values.cast()); + setArrayFloat(name, values.cast()); } else if (first is String) { setArrayString(name, values.cast()); } else { @@ -101,14 +101,14 @@ class Element { } } - /// Sets a double value. - void setDouble(String name, double value) { + /// Sets a float value. + void setFloat(String name, double value) { _ensureNotDisposed(); final namePtr = name.toNativeUtf8(); try { - final error = bindings.psr_element_set_double(_ptr, namePtr.cast(), value); + final error = bindings.psr_element_set_float(_ptr, namePtr.cast(), value); if (error != 0) { - throw DatabaseException.fromError(error, "Failed to set double '$name'"); + throw DatabaseException.fromError(error, "Failed to set float '$name'"); } } finally { malloc.free(namePtr); @@ -175,23 +175,23 @@ class Element { } /// Sets an array of floats. - void setArrayDouble(String name, List values) { + void setArrayFloat(String name, List values) { _ensureNotDisposed(); final namePtr = name.toNativeUtf8(); - final arrayPtr = malloc(values.length); + final arrayPtr = malloc(values.length); try { for (var i = 0; i < values.length; i++) { arrayPtr[i] = values[i]; } - final error = bindings.psr_element_set_array_double( + final error = bindings.psr_element_set_array_float( _ptr, namePtr.cast(), arrayPtr, values.length, ); if (error != 0) { - throw DatabaseException.fromError(error, "Failed to set double array '$name'"); + throw DatabaseException.fromError(error, "Failed to set float array '$name'"); } } finally { malloc.free(namePtr); From fca0a1f458f97864946693326257afb18b3ccc65 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:01:01 -0300 Subject: [PATCH 10/32] update --- bindings/dart/test/read_test.dart | 6 +++--- bindings/dart/test/update_test.dart | 18 +++++++++--------- bindings/julia/src/element.jl | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bindings/dart/test/read_test.dart b/bindings/dart/test/read_test.dart index c12f4b2..2456a94 100644 --- a/bindings/dart/test/read_test.dart +++ b/bindings/dart/test/read_test.dart @@ -443,8 +443,8 @@ void main() { 'float_attribute': 2.71, }); - expect(db.readScalarDoubleById('Configuration', 'float_attribute', 1), equals(3.14)); - expect(db.readScalarDoubleById('Configuration', 'float_attribute', 2), equals(2.71)); + expect(db.readScalarFloatById('Configuration', 'float_attribute', 1), equals(3.14)); + expect(db.readScalarFloatById('Configuration', 'float_attribute', 2), equals(2.71)); } finally { db.close(); } @@ -840,7 +840,7 @@ void main() { 'float_attribute': 3.14, }); - expect(db.readScalarDoubleById('Configuration', 'float_attribute', 999), isNull); + expect(db.readScalarFloatById('Configuration', 'float_attribute', 999), isNull); } finally { db.close(); } diff --git a/bindings/dart/test/update_test.dart b/bindings/dart/test/update_test.dart index 5fb73e3..23625da 100644 --- a/bindings/dart/test/update_test.dart +++ b/bindings/dart/test/update_test.dart @@ -58,7 +58,7 @@ void main() { final intValue = db.readScalarIntegerById('Configuration', 'integer_attribute', 1); expect(intValue, equals(500)); - final floatValue = db.readScalarDoubleById('Configuration', 'float_attribute', 1); + final floatValue = db.readScalarFloatById('Configuration', 'float_attribute', 1); expect(floatValue, equals(9.9)); // Verify label unchanged @@ -245,7 +245,7 @@ void main() { db.updateElement('Configuration', 1, {'float_attribute': 99.99}); - final value = db.readScalarDoubleById('Configuration', 'float_attribute', 1); + final value = db.readScalarFloatById('Configuration', 'float_attribute', 1); expect(value, equals(99.99)); } finally { db.close(); @@ -381,7 +381,7 @@ void main() { }); }); - group('Update Scalar Double', () { + group('Update Scalar Float', () { test('basic update', () { final db = Database.fromSchema( ':memory:', @@ -390,9 +390,9 @@ void main() { try { db.createElement('Configuration', {'label': 'Config 1', 'float_attribute': 3.14}); - db.updateScalarDouble('Configuration', 'float_attribute', 1, 2.71); + db.updateScalarFloat('Configuration', 'float_attribute', 1, 2.71); - final value = db.readScalarDoubleById('Configuration', 'float_attribute', 1); + final value = db.readScalarFloatById('Configuration', 'float_attribute', 1); expect(value, equals(2.71)); } finally { db.close(); @@ -407,9 +407,9 @@ void main() { try { db.createElement('Configuration', {'label': 'Config 1', 'float_attribute': 3.14}); - db.updateScalarDouble('Configuration', 'float_attribute', 1, 0.0); + db.updateScalarFloat('Configuration', 'float_attribute', 1, 0.0); - final value = db.readScalarDoubleById('Configuration', 'float_attribute', 1); + final value = db.readScalarFloatById('Configuration', 'float_attribute', 1); expect(value, equals(0.0)); } finally { db.close(); @@ -424,9 +424,9 @@ void main() { try { db.createElement('Configuration', {'label': 'Config 1', 'float_attribute': 1.0}); - db.updateScalarDouble('Configuration', 'float_attribute', 1, 1.23456789012345); + db.updateScalarFloat('Configuration', 'float_attribute', 1, 1.23456789012345); - final value = db.readScalarDoubleById('Configuration', 'float_attribute', 1); + final value = db.readScalarFloatById('Configuration', 'float_attribute', 1); expect(value, closeTo(1.23456789012345, 1e-10)); } finally { db.close(); diff --git a/bindings/julia/src/element.jl b/bindings/julia/src/element.jl index 2d5ed57..2fd6c93 100644 --- a/bindings/julia/src/element.jl +++ b/bindings/julia/src/element.jl @@ -28,9 +28,9 @@ end function Base.setindex!(el::Element, value::Real, name::String) cname = Base.cconvert(Cstring, name) - err = C.psr_element_set_double(el.ptr, cname, Float64(value)) + err = C.psr_element_set_float(el.ptr, cname, Float64(value)) if err != C.PSR_OK - error("Failed to set double value for '$name'") + error("Failed to set float value for '$name'") end end @@ -55,9 +55,9 @@ end function Base.setindex!(el::Element, value::Vector{<:Real}, name::String) cname = Base.cconvert(Cstring, name) float_values = Float64[Float64(v) for v in value] - err = C.psr_element_set_array_double(el.ptr, cname, float_values, Int32(length(value))) + err = C.psr_element_set_array_float(el.ptr, cname, float_values, Int32(length(value))) if err != C.PSR_OK - error("Failed to set array value for '$name'") + error("Failed to set array value for '$name'") end end From e16a5fc7f55cd76af45ff2d89ad7b086a450a97e Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:01:35 -0300 Subject: [PATCH 11/32] update --- bindings/julia/src/database_read.jl | 10 +++++----- bindings/julia/src/database_update.jl | 6 +++--- bindings/julia/test/test_update.jl | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bindings/julia/src/database_read.jl b/bindings/julia/src/database_read.jl index e0e0c8b..78d8bc6 100644 --- a/bindings/julia/src/database_read.jl +++ b/bindings/julia/src/database_read.jl @@ -60,7 +60,7 @@ function read_scalar_floats(db::Database, collection::String, attribute::String) end result = unsafe_wrap(Array, out_values[], count) |> copy - C.psr_free_double_array(out_values[]) + C.psr_free_float_array(out_values[]) return result end @@ -138,7 +138,7 @@ function read_vector_floats(db::Database, collection::String, attribute::String) push!(result, copy(unsafe_wrap(Array, vectors_ptr[i], sizes_ptr[i]))) end end - C.psr_free_double_vectors(out_vectors[], out_sizes[], count) + C.psr_free_float_vectors(out_vectors[], out_sizes[], count) return result end @@ -226,7 +226,7 @@ function read_set_floats(db::Database, collection::String, attribute::String) push!(result, copy(unsafe_wrap(Array, sets_ptr[i], sizes_ptr[i]))) end end - C.psr_free_double_vectors(out_sets[], out_sizes[], count) + C.psr_free_float_vectors(out_sets[], out_sizes[], count) return result end @@ -345,7 +345,7 @@ function read_vector_floats_by_id(db::Database, collection::String, attribute::S end result = unsafe_wrap(Array, out_values[], count) |> copy - C.psr_free_double_array(out_values[]) + C.psr_free_float_array(out_values[]) return result end @@ -405,7 +405,7 @@ function read_set_floats_by_id(db::Database, collection::String, attribute::Stri end result = unsafe_wrap(Array, out_values[], count) |> copy - C.psr_free_double_array(out_values[]) + C.psr_free_float_array(out_values[]) return result end diff --git a/bindings/julia/src/database_update.jl b/bindings/julia/src/database_update.jl index 0f70452..15710aa 100644 --- a/bindings/julia/src/database_update.jl +++ b/bindings/julia/src/database_update.jl @@ -29,10 +29,10 @@ function update_scalar_integer!(db::Database, collection::String, attribute::Str return nothing end -function update_scalar_double!(db::Database, collection::String, attribute::String, id::Int64, value::Real) - err = C.psr_database_update_scalar_double(db.ptr, collection, attribute, id, Float64(value)) +function update_scalar_float!(db::Database, collection::String, attribute::String, id::Int64, value::Real) + err = C.psr_database_update_scalar_float(db.ptr, collection, attribute, id, Float64(value)) if err != C.PSR_OK - throw(DatabaseException("Failed to update scalar double '$collection.$attribute' for id $id")) + throw(DatabaseException("Failed to update scalar float '$collection.$attribute' for id $id")) end return nothing end diff --git a/bindings/julia/test/test_update.jl b/bindings/julia/test/test_update.jl index f6142f4..5e8da98 100644 --- a/bindings/julia/test/test_update.jl +++ b/bindings/julia/test/test_update.jl @@ -272,24 +272,24 @@ include("fixture.jl") PSRDatabase.close!(db) end - @testset "Scalar Double" begin + @testset "Scalar Float" begin path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") db = PSRDatabase.from_schema(":memory:", path_schema) PSRDatabase.create_element!(db, "Configuration"; label = "Config 1", float_attribute = 3.14) # Basic update - PSRDatabase.update_scalar_double!(db, "Configuration", "float_attribute", Int64(1), 2.71) + PSRDatabase.update_scalar_float!(db, "Configuration", "float_attribute", Int64(1), 2.71) value = PSRDatabase.read_scalar_floats_by_id(db, "Configuration", "float_attribute", Int64(1)) @test value == 2.71 # Update to 0.0 - PSRDatabase.update_scalar_double!(db, "Configuration", "float_attribute", Int64(1), 0.0) + PSRDatabase.update_scalar_float!(db, "Configuration", "float_attribute", Int64(1), 0.0) value = PSRDatabase.read_scalar_floats_by_id(db, "Configuration", "float_attribute", Int64(1)) @test value == 0.0 # Precision test - PSRDatabase.update_scalar_double!(db, "Configuration", "float_attribute", Int64(1), 1.23456789012345) + PSRDatabase.update_scalar_float!(db, "Configuration", "float_attribute", Int64(1), 1.23456789012345) value = PSRDatabase.read_scalar_floats_by_id(db, "Configuration", "float_attribute", Int64(1)) @test value ≈ 1.23456789012345 From 40d889f2302fae6667e401d66ba0a193cd3d7f32 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:01:53 -0300 Subject: [PATCH 12/32] update --- bindings/julia/test/test_element.jl | 2 +- bindings/julia/test/test_read.jl | 4 ++-- include/psr/row.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/julia/test/test_element.jl b/bindings/julia/test/test_element.jl index bfa96f1..d08981e 100644 --- a/bindings/julia/test/test_element.jl +++ b/bindings/julia/test/test_element.jl @@ -10,7 +10,7 @@ # e["double"] = 3.14 # e["string"] = "Hello, World!" # e["vector_int"] = [1, 2, 3, 4, 5] -# e["vector_double"] = [1.1, 2.2, 3.3] +# e["vector_float"] = [1.1, 2.2, 3.3] # # e["vector_string"] = ["one", "two", "three"] # println(e) diff --git a/bindings/julia/test/test_read.jl b/bindings/julia/test/test_read.jl index 3e7620a..d919bac 100644 --- a/bindings/julia/test/test_read.jl +++ b/bindings/julia/test/test_read.jl @@ -565,7 +565,7 @@ include("fixture.jl") PSRDatabase.close!(db) end - @testset "Generic Read - Scalar Double" begin + @testset "Generic Read - Scalar Float" begin path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") db = PSRDatabase.from_schema(":memory:", path_schema) @@ -607,7 +607,7 @@ include("fixture.jl") PSRDatabase.close!(db) end - @testset "Generic Read - Vector Double" begin + @testset "Generic Read - Vector Float" begin path_schema = joinpath(tests_path(), "schemas", "valid", "collections.sql") db = PSRDatabase.from_schema(":memory:", path_schema) diff --git a/include/psr/row.h b/include/psr/row.h index ae25314..5560717 100644 --- a/include/psr/row.h +++ b/include/psr/row.h @@ -23,7 +23,7 @@ class PSR_API Row { // Type-specific getters (return optionals for safe access) bool is_null(size_t index) const; std::optional get_int(size_t index) const; - std::optional get_double(size_t index) const; + std::optional get_float(size_t index) const; std::optional get_string(size_t index) const; // Iterator support From 868cf5c0572d309cf690e5e08a2ab89a4bd03ea7 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:02:27 -0300 Subject: [PATCH 13/32] update --- include/psr/c/database.h | 6 +++--- include/psr/c/element.h | 4 ++-- include/psr/database.h | 2 +- src/row.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/psr/c/database.h b/include/psr/c/database.h index aaacbe4..404c686 100644 --- a/include/psr/c/database.h +++ b/include/psr/c/database.h @@ -222,7 +222,7 @@ PSR_C_API psr_error_t psr_database_update_scalar_integer(psr_database_t* db, int64_t id, int64_t value); -PSR_C_API psr_error_t psr_database_update_scalar_double(psr_database_t* db, +PSR_C_API psr_error_t psr_database_update_scalar_float(psr_database_t* db, const char* collection, const char* attribute, int64_t id, @@ -280,12 +280,12 @@ PSR_C_API psr_error_t psr_database_update_set_strings(psr_database_t* db, // Memory cleanup for read results PSR_C_API void psr_free_int_array(int64_t* values); -PSR_C_API void psr_free_double_array(double* values); +PSR_C_API void psr_free_float_array(double* values); PSR_C_API void psr_free_string_array(char** values, size_t count); // Memory cleanup for vector read results PSR_C_API void psr_free_int_vectors(int64_t** vectors, size_t* sizes, size_t count); -PSR_C_API void psr_free_double_vectors(double** vectors, size_t* sizes, size_t count); +PSR_C_API void psr_free_float_vectors(double** vectors, size_t* sizes, size_t count); PSR_C_API void psr_free_string_vectors(char*** vectors, size_t* sizes, size_t count); #ifdef __cplusplus diff --git a/include/psr/c/element.h b/include/psr/c/element.h index 6ee7ef9..6f3dc58 100644 --- a/include/psr/c/element.h +++ b/include/psr/c/element.h @@ -17,7 +17,7 @@ PSR_C_API void psr_element_clear(psr_element_t* element); // Scalar setters PSR_C_API psr_error_t psr_element_set_integer(psr_element_t* element, const char* name, int64_t value); -PSR_C_API psr_error_t psr_element_set_double(psr_element_t* element, const char* name, double value); +PSR_C_API psr_error_t psr_element_set_float(psr_element_t* element, const char* name, double value); PSR_C_API psr_error_t psr_element_set_string(psr_element_t* element, const char* name, const char* value); PSR_C_API psr_error_t psr_element_set_null(psr_element_t* element, const char* name); @@ -26,7 +26,7 @@ PSR_C_API psr_error_t psr_element_set_array_int(psr_element_t* element, const char* name, const int64_t* values, int32_t count); -PSR_C_API psr_error_t psr_element_set_array_double(psr_element_t* element, +PSR_C_API psr_error_t psr_element_set_array_float(psr_element_t* element, const char* name, const double* values, int32_t count); diff --git a/include/psr/database.h b/include/psr/database.h index daa6bb3..f62f8d0 100644 --- a/include/psr/database.h +++ b/include/psr/database.h @@ -103,7 +103,7 @@ class PSR_API Database { // Update scalar attributes (by element ID) void update_scalar_integer(const std::string& collection, const std::string& attribute, int64_t id, int64_t value); - void update_scalar_double(const std::string& collection, const std::string& attribute, int64_t id, double value); + void update_scalar_float(const std::string& collection, const std::string& attribute, int64_t id, double value); void update_scalar_string(const std::string& collection, const std::string& attribute, int64_t id, diff --git a/src/row.cpp b/src/row.cpp index a8db9b5..d16755a 100644 --- a/src/row.cpp +++ b/src/row.cpp @@ -37,7 +37,7 @@ std::optional Row::get_int(size_t index) const { return std::nullopt; } -std::optional Row::get_double(size_t index) const { +std::optional Row::get_float(size_t index) const { if (index >= values_.size()) return std::nullopt; if (const auto* val = std::get_if(&values_[index])) { From ffe80aefee24422d4619b4795d509b36d6a44458 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:03:03 -0300 Subject: [PATCH 14/32] update --- src/c_api_database.cpp | 8 ++++---- src/c_api_element.cpp | 4 ++-- src/database.cpp | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/c_api_database.cpp b/src/c_api_database.cpp index e40ab3c..58833fb 100644 --- a/src/c_api_database.cpp +++ b/src/c_api_database.cpp @@ -315,7 +315,7 @@ PSR_C_API void psr_free_int_array(int64_t* values) { delete[] values; } -PSR_C_API void psr_free_double_array(double* values) { +PSR_C_API void psr_free_float_array(double* values) { delete[] values; } @@ -403,7 +403,7 @@ PSR_C_API void psr_free_int_vectors(int64_t** vectors, size_t* sizes, size_t cou free_vectors_impl(vectors, sizes, count); } -PSR_C_API void psr_free_double_vectors(double** vectors, size_t* sizes, size_t count) { +PSR_C_API void psr_free_float_vectors(double** vectors, size_t* sizes, size_t count) { free_vectors_impl(vectors, sizes, count); } @@ -729,7 +729,7 @@ PSR_C_API psr_error_t psr_database_update_scalar_integer(psr_database_t* db, } } -PSR_C_API psr_error_t psr_database_update_scalar_double(psr_database_t* db, +PSR_C_API psr_error_t psr_database_update_scalar_float(psr_database_t* db, const char* collection, const char* attribute, int64_t id, @@ -738,7 +738,7 @@ PSR_C_API psr_error_t psr_database_update_scalar_double(psr_database_t* db, return PSR_ERROR_INVALID_ARGUMENT; } try { - db->db.update_scalar_double(collection, attribute, id, value); + db->db.update_scalar_float(collection, attribute, id, value); return PSR_OK; } catch (const std::exception&) { return PSR_ERROR_DATABASE; diff --git a/src/c_api_element.cpp b/src/c_api_element.cpp index 23ea755..3ba142a 100644 --- a/src/c_api_element.cpp +++ b/src/c_api_element.cpp @@ -33,7 +33,7 @@ PSR_C_API psr_error_t psr_element_set_integer(psr_element_t* element, const char return PSR_OK; } -PSR_C_API psr_error_t psr_element_set_double(psr_element_t* element, const char* name, double value) { +PSR_C_API psr_error_t psr_element_set_float(psr_element_t* element, const char* name, double value) { if (!element || !name) { return PSR_ERROR_INVALID_ARGUMENT; } @@ -69,7 +69,7 @@ PSR_C_API psr_error_t psr_element_set_array_int(psr_element_t* element, return PSR_OK; } -PSR_C_API psr_error_t psr_element_set_array_double(psr_element_t* element, +PSR_C_API psr_error_t psr_element_set_array_float(psr_element_t* element, const char* name, const double* values, int32_t count) { diff --git a/src/database.cpp b/src/database.cpp index 6af4bf3..0ca0f1d 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -786,7 +786,7 @@ std::vector Database::read_scalar_floats(const std::string& collection, std::vector values; values.reserve(result.row_count()); for (size_t i = 0; i < result.row_count(); ++i) { - auto val = result[i].get_double(0); + auto val = result[i].get_float(0); if (val) { values.push_back(*val); } @@ -828,7 +828,7 @@ Database::read_scalar_floats_by_id(const std::string& collection, const std::str if (result.empty()) { return std::nullopt; } - return result[0].get_double(0); + return result[0].get_float(0); } std::optional @@ -881,7 +881,7 @@ std::vector> Database::read_vector_floats(const std::string& for (size_t i = 0; i < result.row_count(); ++i) { auto id = result[i].get_int(0); - auto val = result[i].get_double(1); + auto val = result[i].get_float(1); if (!id) continue; @@ -952,7 +952,7 @@ Database::read_vector_floats_by_id(const std::string& collection, const std::str std::vector values; values.reserve(result.row_count()); for (size_t i = 0; i < result.row_count(); ++i) { - auto val = result[i].get_double(0); + auto val = result[i].get_float(0); if (val) { values.push_back(*val); } @@ -1016,7 +1016,7 @@ std::vector> Database::read_set_floats(const std::string& co for (size_t i = 0; i < result.row_count(); ++i) { auto id = result[i].get_int(0); - auto val = result[i].get_double(1); + auto val = result[i].get_float(1); if (!id) continue; @@ -1087,7 +1087,7 @@ Database::read_set_floats_by_id(const std::string& collection, const std::string std::vector values; values.reserve(result.row_count()); for (size_t i = 0; i < result.row_count(); ++i) { - auto val = result[i].get_double(0); + auto val = result[i].get_float(0); if (val) { values.push_back(*val); } @@ -1141,7 +1141,7 @@ void Database::update_scalar_integer(const std::string& collection, impl_->logger->info("Updated {}.{} for id {} to {}", collection, attribute, id, value); } -void Database::update_scalar_double(const std::string& collection, +void Database::update_scalar_float(const std::string& collection, const std::string& attribute, int64_t id, double value) { From c7bf3853f91fb4e100c13579fd3e53db2e0b7428 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:03:46 -0300 Subject: [PATCH 15/32] update --- tests/test_c_api_database_create.cpp | 2 +- tests/test_c_api_database_read.cpp | 22 +++++++++++----------- tests/test_c_api_database_update.cpp | 22 +++++++++++----------- tests/test_c_api_element.cpp | 26 +++++++++++++------------- tests/test_database_errors.cpp | 8 ++++---- tests/test_database_read.cpp | 4 ++-- tests/test_database_update.cpp | 4 ++-- tests/test_element.cpp | 4 ++-- tests/test_lua_runner.cpp | 2 +- tests/test_row_result.cpp | 16 ++++++++-------- 10 files changed, 55 insertions(+), 55 deletions(-) diff --git a/tests/test_c_api_database_create.cpp b/tests/test_c_api_database_create.cpp index b7d3bec..92aeebb 100644 --- a/tests/test_c_api_database_create.cpp +++ b/tests/test_c_api_database_create.cpp @@ -15,7 +15,7 @@ TEST(DatabaseCApi, CreateElementWithScalars) { ASSERT_NE(element, nullptr); psr_element_set_string(element, "label", "Config 1"); psr_element_set_integer(element, "integer_attribute", 42); - psr_element_set_double(element, "float_attribute", 3.14); + psr_element_set_float(element, "float_attribute", 3.14); int64_t id = psr_database_create_element(db, "Configuration", element); EXPECT_EQ(id, 1); diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index f9a08b2..6ab0c58 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -50,13 +50,13 @@ TEST(DatabaseCApi, ReadScalarFloats) { auto e1 = psr_element_create(); psr_element_set_string(e1, "label", "Config 1"); - psr_element_set_double(e1, "float_attribute", 3.14); + psr_element_set_float(e1, "float_attribute", 3.14); psr_database_create_element(db, "Configuration", e1); psr_element_destroy(e1); auto e2 = psr_element_create(); psr_element_set_string(e2, "label", "Config 2"); - psr_element_set_double(e2, "float_attribute", 2.71); + psr_element_set_float(e2, "float_attribute", 2.71); psr_database_create_element(db, "Configuration", e2); psr_element_destroy(e2); @@ -69,7 +69,7 @@ TEST(DatabaseCApi, ReadScalarFloats) { EXPECT_DOUBLE_EQ(values[0], 3.14); EXPECT_DOUBLE_EQ(values[1], 2.71); - psr_free_double_array(values); + psr_free_float_array(values); psr_database_close(db); } @@ -194,14 +194,14 @@ TEST(DatabaseCApi, ReadVectorFloats) { auto e1 = psr_element_create(); psr_element_set_string(e1, "label", "Item 1"); double values1[] = {1.5, 2.5, 3.5}; - psr_element_set_array_double(e1, "value_float", values1, 3); + psr_element_set_array_float(e1, "value_float", values1, 3); psr_database_create_element(db, "Collection", e1); psr_element_destroy(e1); auto e2 = psr_element_create(); psr_element_set_string(e2, "label", "Item 2"); double values2[] = {10.5, 20.5}; - psr_element_set_array_double(e2, "value_float", values2, 2); + psr_element_set_array_float(e2, "value_float", values2, 2); psr_database_create_element(db, "Collection", e2); psr_element_destroy(e2); @@ -220,7 +220,7 @@ TEST(DatabaseCApi, ReadVectorFloats) { EXPECT_DOUBLE_EQ(vectors[1][0], 10.5); EXPECT_DOUBLE_EQ(vectors[1][1], 20.5); - psr_free_double_vectors(vectors, sizes, count); + psr_free_float_vectors(vectors, sizes, count); psr_database_close(db); } @@ -475,7 +475,7 @@ TEST(DatabaseCApi, ReadScalarIntegerById) { psr_database_close(db); } -TEST(DatabaseCApi, ReadScalarDoubleById) { +TEST(DatabaseCApi, ReadScalarFloatById) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("basic.sql").c_str(), &options); @@ -483,7 +483,7 @@ TEST(DatabaseCApi, ReadScalarDoubleById) { auto e1 = psr_element_create(); psr_element_set_string(e1, "label", "Config 1"); - psr_element_set_double(e1, "float_attribute", 3.14); + psr_element_set_float(e1, "float_attribute", 3.14); int64_t id1 = psr_database_create_element(db, "Configuration", e1); psr_element_destroy(e1); @@ -595,7 +595,7 @@ TEST(DatabaseCApi, ReadVectorIntegerById) { psr_database_close(db); } -TEST(DatabaseCApi, ReadVectorDoubleById) { +TEST(DatabaseCApi, ReadVectorFloatById) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("collections.sql").c_str(), &options); @@ -609,7 +609,7 @@ TEST(DatabaseCApi, ReadVectorDoubleById) { auto e1 = psr_element_create(); psr_element_set_string(e1, "label", "Item 1"); double values1[] = {1.5, 2.5, 3.5}; - psr_element_set_array_double(e1, "value_float", values1, 3); + psr_element_set_array_float(e1, "value_float", values1, 3); int64_t id1 = psr_database_create_element(db, "Collection", e1); psr_element_destroy(e1); @@ -623,7 +623,7 @@ TEST(DatabaseCApi, ReadVectorDoubleById) { EXPECT_DOUBLE_EQ(values[1], 2.5); EXPECT_DOUBLE_EQ(values[2], 3.5); - psr_free_double_array(values); + psr_free_float_array(values); psr_database_close(db); } diff --git a/tests/test_c_api_database_update.cpp b/tests/test_c_api_database_update.cpp index 5bd39c2..de1eb37 100644 --- a/tests/test_c_api_database_update.cpp +++ b/tests/test_c_api_database_update.cpp @@ -36,7 +36,7 @@ TEST(DatabaseCApi, UpdateScalarInteger) { psr_database_close(db); } -TEST(DatabaseCApi, UpdateScalarDouble) { +TEST(DatabaseCApi, UpdateScalarFloat) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("basic.sql").c_str(), &options); @@ -44,11 +44,11 @@ TEST(DatabaseCApi, UpdateScalarDouble) { auto e = psr_element_create(); psr_element_set_string(e, "label", "Config 1"); - psr_element_set_double(e, "float_attribute", 3.14); + psr_element_set_float(e, "float_attribute", 3.14); int64_t id = psr_database_create_element(db, "Configuration", e); psr_element_destroy(e); - auto err = psr_database_update_scalar_double(db, "Configuration", "float_attribute", id, 2.71); + auto err = psr_database_update_scalar_float(db, "Configuration", "float_attribute", id, 2.71); EXPECT_EQ(err, PSR_OK); double value; @@ -141,7 +141,7 @@ TEST(DatabaseCApi, UpdateVectorFloats) { auto e = psr_element_create(); psr_element_set_string(e, "label", "Item 1"); double values1[] = {1.5, 2.5, 3.5}; - psr_element_set_array_double(e, "value_float", values1, 3); + psr_element_set_array_float(e, "value_float", values1, 3); int64_t id = psr_database_create_element(db, "Collection", e); psr_element_destroy(e); @@ -157,7 +157,7 @@ TEST(DatabaseCApi, UpdateVectorFloats) { EXPECT_DOUBLE_EQ(read_values[0], 10.5); EXPECT_DOUBLE_EQ(read_values[1], 20.5); - psr_free_double_array(read_values); + psr_free_float_array(read_values); psr_database_close(db); } @@ -318,7 +318,7 @@ TEST(DatabaseCApi, UpdateElementMultipleScalars) { auto e = psr_element_create(); psr_element_set_string(e, "label", "Config 1"); psr_element_set_integer(e, "integer_attribute", 42); - psr_element_set_double(e, "float_attribute", 3.14); + psr_element_set_float(e, "float_attribute", 3.14); psr_element_set_string(e, "string_attribute", "hello"); int64_t id = psr_database_create_element(db, "Configuration", e); psr_element_destroy(e); @@ -326,7 +326,7 @@ TEST(DatabaseCApi, UpdateElementMultipleScalars) { // Update multiple scalar attributes at once auto update = psr_element_create(); psr_element_set_integer(update, "integer_attribute", 100); - psr_element_set_double(update, "float_attribute", 2.71); + psr_element_set_float(update, "float_attribute", 2.71); psr_element_set_string(update, "string_attribute", "world"); auto err = psr_database_update_element(db, "Configuration", id, update); psr_element_destroy(update); @@ -464,18 +464,18 @@ TEST(DatabaseCApi, UpdateScalarIntegerNullAttribute) { psr_database_close(db); } -TEST(DatabaseCApi, UpdateScalarDoubleNullDb) { - auto err = psr_database_update_scalar_double(nullptr, "Configuration", "float_attribute", 1, 3.14); +TEST(DatabaseCApi, UpdateScalarFloatNullDb) { + auto err = psr_database_update_scalar_float(nullptr, "Configuration", "float_attribute", 1, 3.14); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); } -TEST(DatabaseCApi, UpdateScalarDoubleNullCollection) { +TEST(DatabaseCApi, UpdateScalarFloatNullCollection) { auto options = psr_database_options_default(); options.console_level = PSR_LOG_OFF; auto db = psr_database_from_schema(":memory:", VALID_SCHEMA("basic.sql").c_str(), &options); ASSERT_NE(db, nullptr); - auto err = psr_database_update_scalar_double(db, nullptr, "float_attribute", 1, 3.14); + auto err = psr_database_update_scalar_float(db, nullptr, "float_attribute", 1, 3.14); EXPECT_EQ(err, PSR_ERROR_INVALID_ARGUMENT); psr_database_close(db); diff --git a/tests/test_c_api_element.cpp b/tests/test_c_api_element.cpp index 6c73b41..781985b 100644 --- a/tests/test_c_api_element.cpp +++ b/tests/test_c_api_element.cpp @@ -35,11 +35,11 @@ TEST(ElementCApi, SetInt) { psr_element_destroy(element); } -TEST(ElementCApi, SetDouble) { +TEST(ElementCApi, SetFloat) { auto element = psr_element_create(); ASSERT_NE(element, nullptr); - EXPECT_EQ(psr_element_set_double(element, "value", 3.14), PSR_OK); + EXPECT_EQ(psr_element_set_float(element, "value", 3.14), PSR_OK); EXPECT_EQ(psr_element_has_scalars(element), 1); psr_element_destroy(element); @@ -77,12 +77,12 @@ TEST(ElementCApi, SetArrayInt) { psr_element_destroy(element); } -TEST(ElementCApi, SetArrayDouble) { +TEST(ElementCApi, SetArrayFloat) { auto element = psr_element_create(); ASSERT_NE(element, nullptr); double values[] = {1.5, 2.5, 3.5}; - EXPECT_EQ(psr_element_set_array_double(element, "costs", values, 3), PSR_OK); + EXPECT_EQ(psr_element_set_array_float(element, "costs", values, 3), PSR_OK); EXPECT_EQ(psr_element_has_arrays(element), 1); EXPECT_EQ(psr_element_array_count(element), 1); @@ -107,7 +107,7 @@ TEST(ElementCApi, Clear) { psr_element_set_integer(element, "id", 1); double values[] = {1.0, 2.0}; - psr_element_set_array_double(element, "data", values, 2); + psr_element_set_array_float(element, "data", values, 2); EXPECT_EQ(psr_element_has_scalars(element), 1); EXPECT_EQ(psr_element_has_arrays(element), 1); @@ -122,7 +122,7 @@ TEST(ElementCApi, Clear) { TEST(ElementCApi, NullElementErrors) { EXPECT_EQ(psr_element_set_integer(nullptr, "x", 1), PSR_ERROR_INVALID_ARGUMENT); - EXPECT_EQ(psr_element_set_double(nullptr, "x", 1.0), PSR_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(psr_element_set_float(nullptr, "x", 1.0), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_string(nullptr, "x", "y"), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_null(nullptr, "x"), PSR_ERROR_INVALID_ARGUMENT); } @@ -132,7 +132,7 @@ TEST(ElementCApi, NullNameErrors) { ASSERT_NE(element, nullptr); EXPECT_EQ(psr_element_set_integer(element, nullptr, 1), PSR_ERROR_INVALID_ARGUMENT); - EXPECT_EQ(psr_element_set_double(element, nullptr, 1.0), PSR_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(psr_element_set_float(element, nullptr, 1.0), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_string(element, nullptr, "y"), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_null(element, nullptr), PSR_ERROR_INVALID_ARGUMENT); @@ -151,7 +151,7 @@ TEST(ElementCApi, MultipleScalars) { ASSERT_NE(element, nullptr); psr_element_set_string(element, "label", "Plant 1"); - psr_element_set_double(element, "capacity", 50.0); + psr_element_set_float(element, "capacity", 50.0); psr_element_set_integer(element, "id", 1); EXPECT_EQ(psr_element_scalar_count(element), 3); @@ -164,10 +164,10 @@ TEST(ElementCApi, ToString) { ASSERT_NE(element, nullptr); psr_element_set_string(element, "label", "Plant 1"); - psr_element_set_double(element, "capacity", 50.0); + psr_element_set_float(element, "capacity", 50.0); double costs[] = {1.5, 2.5}; - psr_element_set_array_double(element, "costs", costs, 2); + psr_element_set_array_float(element, "costs", costs, 2); char* str = psr_element_to_string(element); ASSERT_NE(str, nullptr); @@ -196,15 +196,15 @@ TEST(ElementCApi, ArrayNullErrors) { const char* string_values[] = {"a", "b", "c"}; EXPECT_EQ(psr_element_set_array_int(nullptr, "x", int_values, 3), PSR_ERROR_INVALID_ARGUMENT); - EXPECT_EQ(psr_element_set_array_double(nullptr, "x", double_values, 3), PSR_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(psr_element_set_array_float(nullptr, "x", double_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_string(nullptr, "x", string_values, 3), PSR_ERROR_INVALID_ARGUMENT); auto element = psr_element_create(); EXPECT_EQ(psr_element_set_array_int(element, nullptr, int_values, 3), PSR_ERROR_INVALID_ARGUMENT); - EXPECT_EQ(psr_element_set_array_double(element, nullptr, double_values, 3), PSR_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(psr_element_set_array_float(element, nullptr, double_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_string(element, nullptr, string_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_int(element, "x", nullptr, 3), PSR_ERROR_INVALID_ARGUMENT); - EXPECT_EQ(psr_element_set_array_double(element, "x", nullptr, 3), PSR_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(psr_element_set_array_float(element, "x", nullptr, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_string(element, "x", nullptr, 3), PSR_ERROR_INVALID_ARGUMENT); psr_element_destroy(element); } diff --git a/tests/test_database_errors.cpp b/tests/test_database_errors.cpp index 5d0dc0c..7d4ae9d 100644 --- a/tests/test_database_errors.cpp +++ b/tests/test_database_errors.cpp @@ -265,10 +265,10 @@ TEST(DatabaseErrors, UpdateScalarIntegerNoSchema) { EXPECT_THROW(db.update_scalar_integer("Configuration", "integer_attribute", 1, 42), std::exception); } -TEST(DatabaseErrors, UpdateScalarDoubleNoSchema) { +TEST(DatabaseErrors, UpdateScalarFloatNoSchema) { psr::Database db(":memory:", {.console_level = psr::LogLevel::off}); - EXPECT_THROW(db.update_scalar_double("Configuration", "float_attribute", 1, 3.14), std::exception); + EXPECT_THROW(db.update_scalar_float("Configuration", "float_attribute", 1, 3.14), std::exception); } TEST(DatabaseErrors, UpdateScalarStringNoSchema) { @@ -446,10 +446,10 @@ TEST(DatabaseErrors, UpdateScalarIntegerCollectionNotFound) { EXPECT_THROW(db.update_scalar_integer("NonexistentCollection", "value", 1, 42), std::runtime_error); } -TEST(DatabaseErrors, UpdateScalarDoubleCollectionNotFound) { +TEST(DatabaseErrors, UpdateScalarFloatCollectionNotFound) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("basic.sql"), {.console_level = psr::LogLevel::off}); - EXPECT_THROW(db.update_scalar_double("NonexistentCollection", "value", 1, 3.14), std::runtime_error); + EXPECT_THROW(db.update_scalar_float("NonexistentCollection", "value", 1, 3.14), std::runtime_error); } TEST(DatabaseErrors, UpdateScalarStringCollectionNotFound) { diff --git a/tests/test_database_read.cpp b/tests/test_database_read.cpp index c7c9cea..aed4964 100644 --- a/tests/test_database_read.cpp +++ b/tests/test_database_read.cpp @@ -268,7 +268,7 @@ TEST(Database, ReadScalarIntegerById) { EXPECT_EQ(*val2, 100); } -TEST(Database, ReadScalarDoubleById) { +TEST(Database, ReadScalarFloatById) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("basic.sql"), {.console_level = psr::LogLevel::off}); psr::Element e1; @@ -347,7 +347,7 @@ TEST(Database, ReadVectorIntegerById) { EXPECT_EQ(vec2, (std::vector{10, 20})); } -TEST(Database, ReadVectorDoubleById) { +TEST(Database, ReadVectorFloatById) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("collections.sql"), {.console_level = psr::LogLevel::off}); diff --git a/tests/test_database_update.cpp b/tests/test_database_update.cpp index 0d10455..22e6b5e 100644 --- a/tests/test_database_update.cpp +++ b/tests/test_database_update.cpp @@ -22,14 +22,14 @@ TEST(Database, UpdateScalarInteger) { EXPECT_EQ(*val, 100); } -TEST(Database, UpdateScalarDouble) { +TEST(Database, UpdateScalarFloat) { auto db = psr::Database::from_schema(":memory:", VALID_SCHEMA("basic.sql"), {.console_level = psr::LogLevel::off}); psr::Element e; e.set("label", std::string("Config 1")).set("float_attribute", 3.14); int64_t id = db.create_element("Configuration", e); - db.update_scalar_double("Configuration", "float_attribute", id, 2.71); + db.update_scalar_float("Configuration", "float_attribute", id, 2.71); auto val = db.read_scalar_floats_by_id("Configuration", "float_attribute", id); EXPECT_TRUE(val.has_value()); diff --git a/tests/test_element.cpp b/tests/test_element.cpp index e0058e4..32454e9 100644 --- a/tests/test_element.cpp +++ b/tests/test_element.cpp @@ -18,7 +18,7 @@ TEST(Element, SetInt) { EXPECT_EQ(std::get(element.scalars().at("count")), 42); } -TEST(Element, SetDouble) { +TEST(Element, SetFloat) { psr::Element element; element.set("value", 3.14); @@ -55,7 +55,7 @@ TEST(Element, SetArrayInt) { EXPECT_EQ(std::get(arrays.at("counts")[2]), 30); } -TEST(Element, SetArrayDouble) { +TEST(Element, SetArrayFloat) { psr::Element element; element.set("values", std::vector{1.5, 2.5, 3.5}); diff --git a/tests/test_lua_runner.cpp b/tests/test_lua_runner.cpp index a8c5084..cc931e9 100644 --- a/tests/test_lua_runner.cpp +++ b/tests/test_lua_runner.cpp @@ -278,7 +278,7 @@ TEST_F(LuaRunnerTest, ReadScalarIntegerByIdFromLua) { lua.run(script); } -TEST_F(LuaRunnerTest, ReadScalarDoubleByIdFromLua) { +TEST_F(LuaRunnerTest, ReadScalarFloatByIdFromLua) { auto db = psr::Database::from_schema(":memory:", collections_schema); db.create_element("Configuration", psr::Element().set("label", "Config")); diff --git a/tests/test_row_result.cpp b/tests/test_row_result.cpp index 1e19526..c9fc3ff 100644 --- a/tests/test_row_result.cpp +++ b/tests/test_row_result.cpp @@ -64,13 +64,13 @@ TEST(Row, GetIntOutOfBounds) { EXPECT_FALSE(result.has_value()); } -TEST(Row, GetDoubleOutOfBounds) { +TEST(Row, GetFloatOutOfBounds) { psr::Row row(std::vector{3.14}); - auto result = row.get_double(1); + auto result = row.get_float(1); EXPECT_FALSE(result.has_value()); - result = row.get_double(100); + result = row.get_float(100); EXPECT_FALSE(result.has_value()); } @@ -91,10 +91,10 @@ TEST(Row, GetIntWrongType) { EXPECT_FALSE(result.has_value()); } -TEST(Row, GetDoubleWrongType) { +TEST(Row, GetFloatWrongType) { psr::Row row(std::vector{std::string("not a double")}); - auto result = row.get_double(0); + auto result = row.get_float(0); EXPECT_FALSE(result.has_value()); } @@ -112,10 +112,10 @@ TEST(Row, GetIntFromNull) { EXPECT_FALSE(result.has_value()); } -TEST(Row, GetDoubleFromNull) { +TEST(Row, GetFloatFromNull) { psr::Row row(std::vector{nullptr}); - auto result = row.get_double(0); + auto result = row.get_float(0); EXPECT_FALSE(result.has_value()); } @@ -232,7 +232,7 @@ TEST(Result, MixedValueTypes) { const auto& row = result[0]; EXPECT_EQ(row.get_int(0).value(), 42); - EXPECT_DOUBLE_EQ(row.get_double(1).value(), 3.14); + EXPECT_DOUBLE_EQ(row.get_float(1).value(), 3.14); EXPECT_EQ(row.get_string(2).value(), "hello"); EXPECT_TRUE(row.is_null(3)); } From cc33d49ac18fbf6b29408e735d9e9d723a79e10f Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:07:24 -0300 Subject: [PATCH 16/32] update --- bindings/julia/src/c_api.jl | 20 ++++++++++---------- bindings/julia/src/database_read.jl | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bindings/julia/src/c_api.jl b/bindings/julia/src/c_api.jl index b776620..6f7d099 100644 --- a/bindings/julia/src/c_api.jl +++ b/bindings/julia/src/c_api.jl @@ -214,8 +214,8 @@ function psr_database_update_scalar_integer(db, collection, attribute, id, value @ccall libpsr_database_c.psr_database_update_scalar_integer(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, value::Int64)::psr_error_t end -function psr_database_update_scalar_double(db, collection, attribute, id, value) - @ccall libpsr_database_c.psr_database_update_scalar_double(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, value::Cdouble)::psr_error_t +function psr_database_update_scalar_float(db, collection, attribute, id, value) + @ccall libpsr_database_c.psr_database_update_scalar_float(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, value::Cdouble)::psr_error_t end function psr_database_update_scalar_string(db, collection, attribute, id, value) @@ -250,8 +250,8 @@ function psr_free_int_array(values) @ccall libpsr_database_c.psr_free_int_array(values::Ptr{Int64})::Cvoid end -function psr_free_double_array(values) - @ccall libpsr_database_c.psr_free_double_array(values::Ptr{Cdouble})::Cvoid +function psr_free_float_array(values) + @ccall libpsr_database_c.psr_free_float_array(values::Ptr{Cdouble})::Cvoid end function psr_free_string_array(values, count) @@ -262,8 +262,8 @@ function psr_free_int_vectors(vectors, sizes, count) @ccall libpsr_database_c.psr_free_int_vectors(vectors::Ptr{Ptr{Int64}}, sizes::Ptr{Csize_t}, count::Csize_t)::Cvoid end -function psr_free_double_vectors(vectors, sizes, count) - @ccall libpsr_database_c.psr_free_double_vectors(vectors::Ptr{Ptr{Cdouble}}, sizes::Ptr{Csize_t}, count::Csize_t)::Cvoid +function psr_free_float_vectors(vectors, sizes, count) + @ccall libpsr_database_c.psr_free_float_vectors(vectors::Ptr{Ptr{Cdouble}}, sizes::Ptr{Csize_t}, count::Csize_t)::Cvoid end function psr_free_string_vectors(vectors, sizes, count) @@ -286,8 +286,8 @@ function psr_element_set_integer(element, name, value) @ccall libpsr_database_c.psr_element_set_integer(element::Ptr{psr_element_t}, name::Ptr{Cchar}, value::Int64)::psr_error_t end -function psr_element_set_double(element, name, value) - @ccall libpsr_database_c.psr_element_set_double(element::Ptr{psr_element_t}, name::Ptr{Cchar}, value::Cdouble)::psr_error_t +function psr_element_set_float(element, name, value) + @ccall libpsr_database_c.psr_element_set_float(element::Ptr{psr_element_t}, name::Ptr{Cchar}, value::Cdouble)::psr_error_t end function psr_element_set_string(element, name, value) @@ -302,8 +302,8 @@ function psr_element_set_array_int(element, name, values, count) @ccall libpsr_database_c.psr_element_set_array_int(element::Ptr{psr_element_t}, name::Ptr{Cchar}, values::Ptr{Int64}, count::Int32)::psr_error_t end -function psr_element_set_array_double(element, name, values, count) - @ccall libpsr_database_c.psr_element_set_array_double(element::Ptr{psr_element_t}, name::Ptr{Cchar}, values::Ptr{Cdouble}, count::Int32)::psr_error_t +function psr_element_set_array_float(element, name, values, count) + @ccall libpsr_database_c.psr_element_set_array_float(element::Ptr{psr_element_t}, name::Ptr{Cchar}, values::Ptr{Cdouble}, count::Int32)::psr_error_t end function psr_element_set_array_string(element, name, values, count) diff --git a/bindings/julia/src/database_read.jl b/bindings/julia/src/database_read.jl index 78d8bc6..a50c3bb 100644 --- a/bindings/julia/src/database_read.jl +++ b/bindings/julia/src/database_read.jl @@ -481,7 +481,7 @@ function read(db::Database, collection::String, attribute::String) elseif attribute_type.data_type == C.PSR_DATA_TYPE_STRING return read_vector_strings(db, collection, attribute) else - throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) + throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) end elseif attribute_type.data_structure == C.PSR_DATA_STRUCTURE_SET if attribute_type.data_type == C.PSR_DATA_TYPE_INTEGER @@ -534,4 +534,4 @@ function read_by_id(db::Database, collection::String, attribute::String, id::Int else throw(DatabaseException("Unsupported data structure for '$collection.$attribute'")) end -end \ No newline at end of file +end From 487316a29c1e34cfb69ccac8b9b0c7e74521fb23 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:07:59 -0300 Subject: [PATCH 17/32] update --- bindings/dart/lib/src/ffi/bindings.dart | 52 ++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/bindings/dart/lib/src/ffi/bindings.dart b/bindings/dart/lib/src/ffi/bindings.dart index 10afc39..91bcb63 100644 --- a/bindings/dart/lib/src/ffi/bindings.dart +++ b/bindings/dart/lib/src/ffi/bindings.dart @@ -870,14 +870,14 @@ class PsrDatabaseBindings { late final _psr_database_update_scalar_integer = _psr_database_update_scalar_integerPtr .asFunction, ffi.Pointer, ffi.Pointer, int, int)>(); - int psr_database_update_scalar_double( + int psr_database_update_scalar_float( ffi.Pointer db, ffi.Pointer collection, ffi.Pointer attribute, int id, double value, ) { - return _psr_database_update_scalar_double( + return _psr_database_update_scalar_float( db, collection, attribute, @@ -886,11 +886,11 @@ class PsrDatabaseBindings { ); } - late final _psr_database_update_scalar_doublePtr = _lookup< + late final _psr_database_update_scalar_floatPtr = _lookup< ffi.NativeFunction< ffi.Int32 Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Int64, - ffi.Double)>>('psr_database_update_scalar_double'); - late final _psr_database_update_scalar_double = _psr_database_update_scalar_doublePtr.asFunction< + ffi.Double)>>('psr_database_update_scalar_float'); + late final _psr_database_update_scalar_float = _psr_database_update_scalar_floatPtr.asFunction< int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, double)>(); int psr_database_update_scalar_string( @@ -1085,17 +1085,17 @@ class PsrDatabaseBindings { _lookup)>>('psr_free_int_array'); late final _psr_free_int_array = _psr_free_int_arrayPtr.asFunction)>(); - void psr_free_double_array( + void psr_free_float_array( ffi.Pointer values, ) { - return _psr_free_double_array( + return _psr_free_float_array( values, ); } - late final _psr_free_double_arrayPtr = - _lookup)>>('psr_free_double_array'); - late final _psr_free_double_array = _psr_free_double_arrayPtr.asFunction)>(); + late final _psr_free_float_arrayPtr = + _lookup)>>('psr_free_float_array'); + late final _psr_free_float_array = _psr_free_float_arrayPtr.asFunction)>(); void psr_free_string_array( ffi.Pointer> values, @@ -1131,22 +1131,22 @@ class PsrDatabaseBindings { late final _psr_free_int_vectors = _psr_free_int_vectorsPtr .asFunction>, ffi.Pointer, int)>(); - void psr_free_double_vectors( + void psr_free_float_vectors( ffi.Pointer> vectors, ffi.Pointer sizes, int count, ) { - return _psr_free_double_vectors( + return _psr_free_float_vectors( vectors, sizes, count, ); } - late final _psr_free_double_vectorsPtr = _lookup< + late final _psr_free_float_vectorsPtr = _lookup< ffi.NativeFunction>, ffi.Pointer, ffi.Size)>>( - 'psr_free_double_vectors'); - late final _psr_free_double_vectors = _psr_free_double_vectorsPtr + 'psr_free_float_vectors'); + late final _psr_free_float_vectors = _psr_free_float_vectorsPtr .asFunction>, ffi.Pointer, int)>(); void psr_free_string_vectors( @@ -1218,23 +1218,23 @@ class PsrDatabaseBindings { late final _psr_element_set_integer = _psr_element_set_integerPtr.asFunction, ffi.Pointer, int)>(); - int psr_element_set_double( + int psr_element_set_float( ffi.Pointer element, ffi.Pointer name, double value, ) { - return _psr_element_set_double( + return _psr_element_set_float( element, name, value, ); } - late final _psr_element_set_doublePtr = + late final _psr_element_set_floatPtr = _lookup, ffi.Pointer, ffi.Double)>>( - 'psr_element_set_double'); - late final _psr_element_set_double = - _psr_element_set_doublePtr.asFunction, ffi.Pointer, double)>(); + 'psr_element_set_float'); + late final _psr_element_set_float = + _psr_element_set_floatPtr.asFunction, ffi.Pointer, double)>(); int psr_element_set_string( ffi.Pointer element, @@ -1292,13 +1292,13 @@ class PsrDatabaseBindings { late final _psr_element_set_array_int = _psr_element_set_array_intPtr .asFunction, ffi.Pointer, ffi.Pointer, int)>(); - int psr_element_set_array_double( + int psr_element_set_array_float( ffi.Pointer element, ffi.Pointer name, ffi.Pointer values, int count, ) { - return _psr_element_set_array_double( + return _psr_element_set_array_float( element, name, values, @@ -1306,11 +1306,11 @@ class PsrDatabaseBindings { ); } - late final _psr_element_set_array_doublePtr = _lookup< + late final _psr_element_set_array_floatPtr = _lookup< ffi.NativeFunction< ffi.Int32 Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, - ffi.Int32)>>('psr_element_set_array_double'); - late final _psr_element_set_array_double = _psr_element_set_array_doublePtr + ffi.Int32)>>('psr_element_set_array_float'); + late final _psr_element_set_array_float = _psr_element_set_array_floatPtr .asFunction, ffi.Pointer, ffi.Pointer, int)>(); int psr_element_set_array_string( From 7062ffe9dd95fd53d38b139e3976c8ef8f4eda01 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:08:21 -0300 Subject: [PATCH 18/32] update --- include/psr/c/database.h | 86 +++++++++++++++--------------- include/psr/c/element.h | 6 +-- include/psr/database.h | 12 ++--- src/c_api_database.cpp | 86 +++++++++++++++--------------- src/c_api_element.cpp | 6 +-- src/database.cpp | 22 ++++---- src/lua_runner.cpp | 36 ++++++------- tests/test_c_api_database_read.cpp | 4 +- 8 files changed, 129 insertions(+), 129 deletions(-) diff --git a/include/psr/c/database.h b/include/psr/c/database.h index 404c686..1861180 100644 --- a/include/psr/c/database.h +++ b/include/psr/c/database.h @@ -81,10 +81,10 @@ PSR_C_API psr_error_t psr_database_read_scalar_integers(psr_database_t* db, size_t* out_count); PSR_C_API psr_error_t psr_database_read_scalar_floats(psr_database_t* db, - const char* collection, - const char* attribute, - double** out_values, - size_t* out_count); + const char* collection, + const char* attribute, + double** out_values, + size_t* out_count); PSR_C_API psr_error_t psr_database_read_scalar_strings(psr_database_t* db, const char* collection, @@ -101,11 +101,11 @@ PSR_C_API psr_error_t psr_database_read_vector_integers(psr_database_t* db, size_t* out_count); PSR_C_API psr_error_t psr_database_read_vector_floats(psr_database_t* db, - const char* collection, - const char* attribute, - double*** out_vectors, - size_t** out_sizes, - size_t* out_count); + const char* collection, + const char* attribute, + double*** out_vectors, + size_t** out_sizes, + size_t* out_count); PSR_C_API psr_error_t psr_database_read_vector_strings(psr_database_t* db, const char* collection, @@ -123,11 +123,11 @@ PSR_C_API psr_error_t psr_database_read_set_integers(psr_database_t* db, size_t* out_count); PSR_C_API psr_error_t psr_database_read_set_floats(psr_database_t* db, - const char* collection, - const char* attribute, - double*** out_sets, - size_t** out_sizes, - size_t* out_count); + const char* collection, + const char* attribute, + double*** out_sets, + size_t** out_sizes, + size_t* out_count); PSR_C_API psr_error_t psr_database_read_set_strings(psr_database_t* db, const char* collection, @@ -145,11 +145,11 @@ PSR_C_API psr_error_t psr_database_read_scalar_integers_by_id(psr_database_t* db int* out_has_value); PSR_C_API psr_error_t psr_database_read_scalar_floats_by_id(psr_database_t* db, - const char* collection, - const char* attribute, - int64_t id, - double* out_value, - int* out_has_value); + const char* collection, + const char* attribute, + int64_t id, + double* out_value, + int* out_has_value); PSR_C_API psr_error_t psr_database_read_scalar_strings_by_id(psr_database_t* db, const char* collection, @@ -167,11 +167,11 @@ PSR_C_API psr_error_t psr_database_read_vector_integers_by_id(psr_database_t* db size_t* out_count); PSR_C_API psr_error_t psr_database_read_vector_floats_by_id(psr_database_t* db, - const char* collection, - const char* attribute, - int64_t id, - double** out_values, - size_t* out_count); + const char* collection, + const char* attribute, + int64_t id, + double** out_values, + size_t* out_count); PSR_C_API psr_error_t psr_database_read_vector_strings_by_id(psr_database_t* db, const char* collection, @@ -189,11 +189,11 @@ PSR_C_API psr_error_t psr_database_read_set_integers_by_id(psr_database_t* db, size_t* out_count); PSR_C_API psr_error_t psr_database_read_set_floats_by_id(psr_database_t* db, - const char* collection, - const char* attribute, - int64_t id, - double** out_values, - size_t* out_count); + const char* collection, + const char* attribute, + int64_t id, + double** out_values, + size_t* out_count); PSR_C_API psr_error_t psr_database_read_set_strings_by_id(psr_database_t* db, const char* collection, @@ -223,10 +223,10 @@ PSR_C_API psr_error_t psr_database_update_scalar_integer(psr_database_t* db, int64_t value); PSR_C_API psr_error_t psr_database_update_scalar_float(psr_database_t* db, - const char* collection, - const char* attribute, - int64_t id, - double value); + const char* collection, + const char* attribute, + int64_t id, + double value); PSR_C_API psr_error_t psr_database_update_scalar_string(psr_database_t* db, const char* collection, @@ -243,11 +243,11 @@ PSR_C_API psr_error_t psr_database_update_vector_integers(psr_database_t* db, size_t count); PSR_C_API psr_error_t psr_database_update_vector_floats(psr_database_t* db, - const char* collection, - const char* attribute, - int64_t id, - const double* values, - size_t count); + const char* collection, + const char* attribute, + int64_t id, + const double* values, + size_t count); PSR_C_API psr_error_t psr_database_update_vector_strings(psr_database_t* db, const char* collection, @@ -265,11 +265,11 @@ PSR_C_API psr_error_t psr_database_update_set_integers(psr_database_t* db, size_t count); PSR_C_API psr_error_t psr_database_update_set_floats(psr_database_t* db, - const char* collection, - const char* attribute, - int64_t id, - const double* values, - size_t count); + const char* collection, + const char* attribute, + int64_t id, + const double* values, + size_t count); PSR_C_API psr_error_t psr_database_update_set_strings(psr_database_t* db, const char* collection, diff --git a/include/psr/c/element.h b/include/psr/c/element.h index 6f3dc58..f74d2c5 100644 --- a/include/psr/c/element.h +++ b/include/psr/c/element.h @@ -27,9 +27,9 @@ PSR_C_API psr_error_t psr_element_set_array_int(psr_element_t* element, const int64_t* values, int32_t count); PSR_C_API psr_error_t psr_element_set_array_float(psr_element_t* element, - const char* name, - const double* values, - int32_t count); + const char* name, + const double* values, + int32_t count); PSR_C_API psr_error_t psr_element_set_array_string(psr_element_t* element, const char* name, const char* const* values, diff --git a/include/psr/database.h b/include/psr/database.h index f62f8d0..c66a5ce 100644 --- a/include/psr/database.h +++ b/include/psr/database.h @@ -115,9 +115,9 @@ class PSR_API Database { int64_t id, const std::vector& values); void update_vector_floats(const std::string& collection, - const std::string& attribute, - int64_t id, - const std::vector& values); + const std::string& attribute, + int64_t id, + const std::vector& values); void update_vector_strings(const std::string& collection, const std::string& attribute, int64_t id, @@ -129,9 +129,9 @@ class PSR_API Database { int64_t id, const std::vector& values); void update_set_floats(const std::string& collection, - const std::string& attribute, - int64_t id, - const std::vector& values); + const std::string& attribute, + int64_t id, + const std::vector& values); void update_set_strings(const std::string& collection, const std::string& attribute, int64_t id, diff --git a/src/c_api_database.cpp b/src/c_api_database.cpp index 58833fb..308d21c 100644 --- a/src/c_api_database.cpp +++ b/src/c_api_database.cpp @@ -269,10 +269,10 @@ PSR_C_API psr_error_t psr_database_read_scalar_integers(psr_database_t* db, } PSR_C_API psr_error_t psr_database_read_scalar_floats(psr_database_t* db, - const char* collection, - const char* attribute, - double** out_values, - size_t* out_count) { + const char* collection, + const char* attribute, + double** out_values, + size_t* out_count) { if (!db || !collection || !attribute || !out_values || !out_count) { return PSR_ERROR_INVALID_ARGUMENT; } @@ -346,11 +346,11 @@ PSR_C_API psr_error_t psr_database_read_vector_integers(psr_database_t* db, } PSR_C_API psr_error_t psr_database_read_vector_floats(psr_database_t* db, - const char* collection, - const char* attribute, - double*** out_vectors, - size_t** out_sizes, - size_t* out_count) { + const char* collection, + const char* attribute, + double*** out_vectors, + size_t** out_sizes, + size_t* out_count) { if (!db || !collection || !attribute || !out_vectors || !out_sizes || !out_count) { return PSR_ERROR_INVALID_ARGUMENT; } @@ -442,11 +442,11 @@ PSR_C_API psr_error_t psr_database_read_set_integers(psr_database_t* db, } PSR_C_API psr_error_t psr_database_read_set_floats(psr_database_t* db, - const char* collection, - const char* attribute, - double*** out_sets, - size_t** out_sizes, - size_t* out_count) { + const char* collection, + const char* attribute, + double*** out_sets, + size_t** out_sizes, + size_t* out_count) { if (!db || !collection || !attribute || !out_sets || !out_sizes || !out_count) { return PSR_ERROR_INVALID_ARGUMENT; } @@ -521,11 +521,11 @@ PSR_C_API psr_error_t psr_database_read_scalar_integers_by_id(psr_database_t* db } PSR_C_API psr_error_t psr_database_read_scalar_floats_by_id(psr_database_t* db, - const char* collection, - const char* attribute, - int64_t id, - double* out_value, - int* out_has_value) { + const char* collection, + const char* attribute, + int64_t id, + double* out_value, + int* out_has_value) { if (!db || !collection || !attribute || !out_value || !out_has_value) { return PSR_ERROR_INVALID_ARGUMENT; } @@ -589,11 +589,11 @@ PSR_C_API psr_error_t psr_database_read_vector_integers_by_id(psr_database_t* db } PSR_C_API psr_error_t psr_database_read_vector_floats_by_id(psr_database_t* db, - const char* collection, - const char* attribute, - int64_t id, - double** out_values, - size_t* out_count) { + const char* collection, + const char* attribute, + int64_t id, + double** out_values, + size_t* out_count) { if (!db || !collection || !attribute || !out_values || !out_count) { return PSR_ERROR_INVALID_ARGUMENT; } @@ -653,11 +653,11 @@ PSR_C_API psr_error_t psr_database_read_set_integers_by_id(psr_database_t* db, } PSR_C_API psr_error_t psr_database_read_set_floats_by_id(psr_database_t* db, - const char* collection, - const char* attribute, - int64_t id, - double** out_values, - size_t* out_count) { + const char* collection, + const char* attribute, + int64_t id, + double** out_values, + size_t* out_count) { if (!db || !collection || !attribute || !out_values || !out_count) { return PSR_ERROR_INVALID_ARGUMENT; } @@ -730,10 +730,10 @@ PSR_C_API psr_error_t psr_database_update_scalar_integer(psr_database_t* db, } PSR_C_API psr_error_t psr_database_update_scalar_float(psr_database_t* db, - const char* collection, - const char* attribute, - int64_t id, - double value) { + const char* collection, + const char* attribute, + int64_t id, + double value) { if (!db || !collection || !attribute) { return PSR_ERROR_INVALID_ARGUMENT; } @@ -782,11 +782,11 @@ PSR_C_API psr_error_t psr_database_update_vector_integers(psr_database_t* db, } PSR_C_API psr_error_t psr_database_update_vector_floats(psr_database_t* db, - const char* collection, - const char* attribute, - int64_t id, - const double* values, - size_t count) { + const char* collection, + const char* attribute, + int64_t id, + const double* values, + size_t count) { if (!db || !collection || !attribute || (count > 0 && !values)) { return PSR_ERROR_INVALID_ARGUMENT; } @@ -842,11 +842,11 @@ PSR_C_API psr_error_t psr_database_update_set_integers(psr_database_t* db, } PSR_C_API psr_error_t psr_database_update_set_floats(psr_database_t* db, - const char* collection, - const char* attribute, - int64_t id, - const double* values, - size_t count) { + const char* collection, + const char* attribute, + int64_t id, + const double* values, + size_t count) { if (!db || !collection || !attribute || (count > 0 && !values)) { return PSR_ERROR_INVALID_ARGUMENT; } diff --git a/src/c_api_element.cpp b/src/c_api_element.cpp index 3ba142a..8206177 100644 --- a/src/c_api_element.cpp +++ b/src/c_api_element.cpp @@ -70,9 +70,9 @@ PSR_C_API psr_error_t psr_element_set_array_int(psr_element_t* element, } PSR_C_API psr_error_t psr_element_set_array_float(psr_element_t* element, - const char* name, - const double* values, - int32_t count) { + const char* name, + const double* values, + int32_t count) { if (!element || !name || (!values && count > 0) || count < 0) { return PSR_ERROR_INVALID_ARGUMENT; } diff --git a/src/database.cpp b/src/database.cpp index 0ca0f1d..d0d2f61 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -871,7 +871,7 @@ std::vector> Database::read_vector_integers(const std::stri } std::vector> Database::read_vector_floats(const std::string& collection, - const std::string& attribute) { + const std::string& attribute) { auto vector_table = impl_->schema->find_vector_table(collection, attribute); auto sql = "SELECT id, " + attribute + " FROM " + vector_table + " ORDER BY id, vector_index"; auto result = execute(sql); @@ -1006,7 +1006,7 @@ std::vector> Database::read_set_integers(const std::string& } std::vector> Database::read_set_floats(const std::string& collection, - const std::string& attribute) { + const std::string& attribute) { auto set_table = impl_->schema->find_set_table(collection, attribute); auto sql = "SELECT id, " + attribute + " FROM " + set_table + " ORDER BY id"; auto result = execute(sql); @@ -1142,9 +1142,9 @@ void Database::update_scalar_integer(const std::string& collection, } void Database::update_scalar_float(const std::string& collection, - const std::string& attribute, - int64_t id, - double value) { + const std::string& attribute, + int64_t id, + double value) { impl_->logger->debug("Updating {}.{} for id {} to {}", collection, attribute, id, value); impl_->require_collection(collection, "update scalar"); impl_->type_validator->validate_scalar(collection, attribute, value); @@ -1199,9 +1199,9 @@ void Database::update_vector_integers(const std::string& collection, } void Database::update_vector_floats(const std::string& collection, - const std::string& attribute, - int64_t id, - const std::vector& values) { + const std::string& attribute, + int64_t id, + const std::vector& values) { impl_->logger->debug("Updating vector {}.{} for id {} with {} values", collection, attribute, id, values.size()); impl_->require_schema("update vector"); @@ -1285,9 +1285,9 @@ void Database::update_set_integers(const std::string& collection, } void Database::update_set_floats(const std::string& collection, - const std::string& attribute, - int64_t id, - const std::vector& values) { + const std::string& attribute, + int64_t id, + const std::vector& values) { impl_->logger->debug("Updating set {}.{} for id {} with {} values", collection, attribute, id, values.size()); impl_->require_schema("update set"); diff --git a/src/lua_runner.cpp b/src/lua_runner.cpp index c5a6c88..032cbd3 100644 --- a/src/lua_runner.cpp +++ b/src/lua_runner.cpp @@ -197,9 +197,9 @@ struct LuaRunner::Impl { } static sol::table read_scalar_floats_to_lua(Database& db, - const std::string& collection, - const std::string& attribute, - sol::this_state s) { + const std::string& collection, + const std::string& attribute, + sol::this_state s) { sol::state_view lua(s); auto result = db.read_scalar_floats(collection, attribute); sol::table t = lua.create_table(); @@ -227,9 +227,9 @@ struct LuaRunner::Impl { } static sol::table read_vector_floats_to_lua(Database& db, - const std::string& collection, - const std::string& attribute, - sol::this_state s) { + const std::string& collection, + const std::string& attribute, + sol::this_state s) { sol::state_view lua(s); auto result = db.read_vector_floats(collection, attribute); sol::table outer = lua.create_table(); @@ -288,10 +288,10 @@ struct LuaRunner::Impl { } static sol::object read_scalar_floats_by_id_to_lua(Database& db, - const std::string& collection, - const std::string& attribute, - int64_t id, - sol::this_state s) { + const std::string& collection, + const std::string& attribute, + int64_t id, + sol::this_state s) { sol::state_view lua(s); auto result = db.read_scalar_floats_by_id(collection, attribute, id); if (result.has_value()) { @@ -316,10 +316,10 @@ struct LuaRunner::Impl { } static sol::table read_vector_floats_by_id_to_lua(Database& db, - const std::string& collection, - const std::string& attribute, - int64_t id, - sol::this_state s) { + const std::string& collection, + const std::string& attribute, + int64_t id, + sol::this_state s) { sol::state_view lua(s); auto result = db.read_vector_floats_by_id(collection, attribute, id); sol::table t = lua.create_table(); @@ -359,10 +359,10 @@ struct LuaRunner::Impl { } static sol::table read_set_floats_by_id_to_lua(Database& db, - const std::string& collection, - const std::string& attribute, - int64_t id, - sol::this_state s) { + const std::string& collection, + const std::string& attribute, + int64_t id, + sol::this_state s) { sol::state_view lua(s); auto result = db.read_set_floats_by_id(collection, attribute, id); sol::table t = lua.create_table(); diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index 6ab0c58..90e0ddd 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -247,8 +247,8 @@ TEST(DatabaseCApi, ReadVectorEmpty) { double** double_vectors = nullptr; size_t* double_sizes = nullptr; size_t double_count = 0; - err = psr_database_read_vector_floats( - db, "Collection", "value_float", &double_vectors, &double_sizes, &double_count); + err = + psr_database_read_vector_floats(db, "Collection", "value_float", &double_vectors, &double_sizes, &double_count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(double_count, 0); EXPECT_EQ(double_vectors, nullptr); From 45e507bdd28c21587d4a21c1e36ac8aa703fb287 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:08:47 -0300 Subject: [PATCH 19/32] update --- bindings/dart/lib/src/element.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/dart/lib/src/element.dart b/bindings/dart/lib/src/element.dart index ebd7ebd..7aa6d98 100644 --- a/bindings/dart/lib/src/element.dart +++ b/bindings/dart/lib/src/element.dart @@ -178,7 +178,7 @@ class Element { void setArrayFloat(String name, List values) { _ensureNotDisposed(); final namePtr = name.toNativeUtf8(); - final arrayPtr = malloc(values.length); + final arrayPtr = malloc(values.length); try { for (var i = 0; i < values.length; i++) { From 14b54ba19ffe4e66f4332035472e37669dfb597d Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:10:53 -0300 Subject: [PATCH 20/32] update --- bindings/dart/lib/src/database.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bindings/dart/lib/src/database.dart b/bindings/dart/lib/src/database.dart index b6b76e0..c4d34e6 100644 --- a/bindings/dart/lib/src/database.dart +++ b/bindings/dart/lib/src/database.dart @@ -572,7 +572,7 @@ class Database { ); if (err != psr_error_t.PSR_OK) { - throw DatabaseException.fromError(err, "Failed to read scalar double by id from '$collection.$attribute'"); + throw DatabaseException.fromError(err, "Failed to read scalar float by id from '$collection.$attribute'"); } if (outHasValue.value == 0) { @@ -655,7 +655,7 @@ class Database { } } - /// Reads double vector for a vector attribute by element ID. + /// Reads float vector for a vector attribute by element ID. List readVectorFloatsById(String collection, String attribute, int id) { _ensureNotClosed(); @@ -762,7 +762,7 @@ class Database { } } - /// Reads double set for a set attribute by element ID. + /// Reads float set for a set attribute by element ID. List readSetFloatsById(String collection, String attribute, int id) { _ensureNotClosed(); @@ -988,7 +988,7 @@ class Database { } } - /// Updates a double scalar attribute value by element ID. + /// Updates a float scalar attribute value by element ID. void updateScalarFloat(String collection, String attribute, int id, double value) { _ensureNotClosed(); @@ -1003,7 +1003,7 @@ class Database { ); if (err != psr_error_t.PSR_OK) { - throw DatabaseException.fromError(err, "Failed to update scalar double '$collection.$attribute' for id $id"); + throw DatabaseException.fromError(err, "Failed to update scalar float '$collection.$attribute' for id $id"); } } finally { arena.releaseAll(); @@ -1062,7 +1062,7 @@ class Database { } } - /// Updates a double vector attribute by element ID (replaces entire vector). + /// Updates a float vector attribute by element ID (replaces entire vector). void updateVectorFloats(String collection, String attribute, int id, List values) { _ensureNotClosed(); @@ -1148,7 +1148,7 @@ class Database { } } - /// Updates a double set attribute by element ID (replaces entire set). + /// Updates a float set attribute by element ID (replaces entire set). void updateSetFloats(String collection, String attribute, int id, List values) { _ensureNotClosed(); From 8e2445773f694809cb503d13278fd597dd4727a4 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:16:49 -0300 Subject: [PATCH 21/32] update --- bindings/julia/src/PSRDatabase.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/bindings/julia/src/PSRDatabase.jl b/bindings/julia/src/PSRDatabase.jl index ef63eb4..0f50cf6 100644 --- a/bindings/julia/src/PSRDatabase.jl +++ b/bindings/julia/src/PSRDatabase.jl @@ -13,9 +13,6 @@ include("database_delete.jl") include("lua_runner.jl") export Element, Database, LuaRunner, DatabaseException -export get_attribute_type -export PSR_DATA_STRUCTURE_SCALAR, PSR_DATA_STRUCTURE_VECTOR, PSR_DATA_STRUCTURE_SET -export PSR_DATA_TYPE_INTEGER, PSR_DATA_TYPE_FLOAT, PSR_DATA_TYPE_STRING # Re-export enums from C module const PSR_DATA_STRUCTURE_SCALAR = C.PSR_DATA_STRUCTURE_SCALAR From f474226e68f36d4a5544dfdb5a1bbe823b3e7c42 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:19:33 -0300 Subject: [PATCH 22/32] update --- bindings/dart/test/lua_runner_test.dart | 4 ++-- bindings/dart/test/read_test.dart | 8 ++++---- bindings/julia/src/database_read.jl | 2 +- bindings/julia/test/test_element.jl | 21 --------------------- bindings/julia/test/test_lua_runner.jl | 4 ++-- tests/test_c_api_database_read.cpp | 6 +++--- tests/test_c_api_element.cpp | 6 +++--- 7 files changed, 15 insertions(+), 36 deletions(-) delete mode 100644 bindings/julia/test/test_element.jl diff --git a/bindings/dart/test/lua_runner_test.dart b/bindings/dart/test/lua_runner_test.dart index f204657..1c9962a 100644 --- a/bindings/dart/test/lua_runner_test.dart +++ b/bindings/dart/test/lua_runner_test.dart @@ -251,8 +251,8 @@ void main() { lua.run(''' local floats = db:read_scalar_floats("Collection", "some_float") assert(#floats == 2, "Expected 2 floats") - assert(floats[1] == 1.5, "First double mismatch") - assert(floats[2] == 2.5, "Second double mismatch") + assert(floats[1] == 1.5, "First float mismatch") + assert(floats[2] == 2.5, "Second float mismatch") '''); } finally { lua.dispose(); diff --git a/bindings/dart/test/read_test.dart b/bindings/dart/test/read_test.dart index 2456a94..fa0493a 100644 --- a/bindings/dart/test/read_test.dart +++ b/bindings/dart/test/read_test.dart @@ -173,7 +173,7 @@ void main() { } }); - test('reads double vectors from Collection', () { + test('reads float vectors from Collection', () { final db = Database.fromSchema( ':memory:', path.join(testsPath, 'schemas', 'valid', 'collections.sql'), @@ -428,7 +428,7 @@ void main() { }); group('Read Scalar Floats by ID', () { - test('reads double by specific element ID', () { + test('reads float by specific element ID', () { final db = Database.fromSchema( ':memory:', path.join(testsPath, 'schemas', 'valid', 'basic.sql'), @@ -501,7 +501,7 @@ void main() { }); group('Read Vector Floats by ID', () { - test('reads double vector by specific element ID', () { + test('reads float vector by specific element ID', () { final db = Database.fromSchema( ':memory:', path.join(testsPath, 'schemas', 'valid', 'collections.sql'), @@ -829,7 +829,7 @@ void main() { } }); - test('returns null for nonexistent double ID', () { + test('returns null for nonexistent float ID', () { final db = Database.fromSchema( ':memory:', path.join(testsPath, 'schemas', 'valid', 'basic.sql'), diff --git a/bindings/julia/src/database_read.jl b/bindings/julia/src/database_read.jl index a50c3bb..0d70eeb 100644 --- a/bindings/julia/src/database_read.jl +++ b/bindings/julia/src/database_read.jl @@ -283,7 +283,7 @@ function read_scalar_floats_by_id(db::Database, collection::String, attribute::S err = C.psr_database_read_scalar_floats_by_id(db.ptr, collection, attribute, id, out_value, out_has_value) if err != C.PSR_OK - throw(DatabaseException("Failed to read scalar double by id from '$collection.$attribute'")) + throw(DatabaseException("Failed to read scalar float by id from '$collection.$attribute'")) end if out_has_value[] == 0 diff --git a/bindings/julia/test/test_element.jl b/bindings/julia/test/test_element.jl deleted file mode 100644 index d08981e..0000000 --- a/bindings/julia/test/test_element.jl +++ /dev/null @@ -1,21 +0,0 @@ -# module TestElement - -# using PSRDatabase -# using Test - -# @testset "Element" begin -# e = Element() - -# e["integer"] = 42 -# e["double"] = 3.14 -# e["string"] = "Hello, World!" -# e["vector_int"] = [1, 2, 3, 4, 5] -# e["vector_float"] = [1.1, 2.2, 3.3] -# # e["vector_string"] = ["one", "two", "three"] - -# println(e) - -# return nothing -# end - -# end diff --git a/bindings/julia/test/test_lua_runner.jl b/bindings/julia/test/test_lua_runner.jl index 2f4ef6f..9d1fead 100644 --- a/bindings/julia/test/test_lua_runner.jl +++ b/bindings/julia/test/test_lua_runner.jl @@ -187,8 +187,8 @@ include("fixture.jl") """ local floats = db:read_scalar_floats("Collection", "some_float") assert(#floats == 2, "Expected 2 floats") - assert(floats[1] == 1.5, "First double mismatch") - assert(floats[2] == 2.5, "Second double mismatch") + assert(floats[1] == 1.5, "First float mismatch") + assert(floats[2] == 2.5, "Second float mismatch") """, ) diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index 90e0ddd..6aea538 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -122,12 +122,12 @@ TEST(DatabaseCApi, ReadScalarEmpty) { EXPECT_EQ(int_count, 0); EXPECT_EQ(int_values, nullptr); - double* double_values = nullptr; + double* float_values = nullptr; size_t double_count = 0; - err = psr_database_read_scalar_floats(db, "Collection", "some_float", &double_values, &double_count); + err = psr_database_read_scalar_floats(db, "Collection", "some_float", &float_values, &double_count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(double_count, 0); - EXPECT_EQ(double_values, nullptr); + EXPECT_EQ(float_values, nullptr); psr_database_close(db); } diff --git a/tests/test_c_api_element.cpp b/tests/test_c_api_element.cpp index 781985b..d7d2038 100644 --- a/tests/test_c_api_element.cpp +++ b/tests/test_c_api_element.cpp @@ -192,16 +192,16 @@ TEST(ElementCApi, StringFreeNull) { TEST(ElementCApi, ArrayNullErrors) { int64_t int_values[] = {1, 2, 3}; - double double_values[] = {1.0, 2.0, 3.0}; + double float_values[] = {1.0, 2.0, 3.0}; const char* string_values[] = {"a", "b", "c"}; EXPECT_EQ(psr_element_set_array_int(nullptr, "x", int_values, 3), PSR_ERROR_INVALID_ARGUMENT); - EXPECT_EQ(psr_element_set_array_float(nullptr, "x", double_values, 3), PSR_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(psr_element_set_array_float(nullptr, "x", float_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_string(nullptr, "x", string_values, 3), PSR_ERROR_INVALID_ARGUMENT); auto element = psr_element_create(); EXPECT_EQ(psr_element_set_array_int(element, nullptr, int_values, 3), PSR_ERROR_INVALID_ARGUMENT); - EXPECT_EQ(psr_element_set_array_float(element, nullptr, double_values, 3), PSR_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(psr_element_set_array_float(element, nullptr, float_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_string(element, nullptr, string_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_int(element, "x", nullptr, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_float(element, "x", nullptr, 3), PSR_ERROR_INVALID_ARGUMENT); From c7ebe1eaefb6158a00d7fbb5d560caf97249537f Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:20:52 -0300 Subject: [PATCH 23/32] update --- bindings/julia/src/database_update.jl | 10 +++++----- bindings/julia/src/element.jl | 4 ++-- tests/test_c_api_database_read.cpp | 28 +++++++++++++-------------- tests/test_c_api_element.cpp | 6 +++--- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/bindings/julia/src/database_update.jl b/bindings/julia/src/database_update.jl index 15710aa..e1cb7c1 100644 --- a/bindings/julia/src/database_update.jl +++ b/bindings/julia/src/database_update.jl @@ -54,14 +54,14 @@ function update_vector_integers!( id::Int64, values::Vector{<:Integer}, ) - int_values = Int64[Int64(v) for v in values] + integer_values = Int64[Int64(v) for v in values] err = C.psr_database_update_vector_integers( db.ptr, collection, attribute, id, - int_values, - Csize_t(length(int_values)), + integer_values, + Csize_t(length(integer_values)), ) if err != C.PSR_OK throw(DatabaseException("Failed to update vector integers '$collection.$attribute' for id $id")) @@ -106,8 +106,8 @@ end # Update set attribute functions function update_set_integers!(db::Database, collection::String, attribute::String, id::Int64, values::Vector{<:Integer}) - int_values = Int64[Int64(v) for v in values] - err = C.psr_database_update_set_integers(db.ptr, collection, attribute, id, int_values, Csize_t(length(int_values))) + integer_values = Int64[Int64(v) for v in values] + err = C.psr_database_update_set_integers(db.ptr, collection, attribute, id, integer_values, Csize_t(length(integer_values))) if err != C.PSR_OK throw(DatabaseException("Failed to update set integers '$collection.$attribute' for id $id")) end diff --git a/bindings/julia/src/element.jl b/bindings/julia/src/element.jl index 2fd6c93..7819500 100644 --- a/bindings/julia/src/element.jl +++ b/bindings/julia/src/element.jl @@ -45,8 +45,8 @@ end function Base.setindex!(el::Element, value::Vector{<:Integer}, name::String) cname = Base.cconvert(Cstring, name) - int_values = Int64[Int64(v) for v in value] - err = C.psr_element_set_array_int(el.ptr, cname, int_values, Int32(length(int_values))) + integer_values = Int64[Int64(v) for v in value] + err = C.psr_element_set_array_int(el.ptr, cname, integer_values, Int32(length(integer_values))) if err != C.PSR_OK error("Failed to set array value for '$name'") end diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index 6aea538..081c221 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -115,18 +115,18 @@ TEST(DatabaseCApi, ReadScalarEmpty) { psr_database_create_element(db, "Configuration", config); psr_element_destroy(config); - int64_t* int_values = nullptr; - size_t int_count = 0; - auto err = psr_database_read_scalar_integers(db, "Collection", "some_integer", &int_values, &int_count); + int64_t* integer_values = nullptr; + size_t integer_count = 0; + auto err = psr_database_read_scalar_integers(db, "Collection", "some_integer", &integer_values, &integer_count); EXPECT_EQ(err, PSR_OK); - EXPECT_EQ(int_count, 0); - EXPECT_EQ(int_values, nullptr); + EXPECT_EQ(integer_count, 0); + EXPECT_EQ(integer_values, nullptr); double* float_values = nullptr; - size_t double_count = 0; - err = psr_database_read_scalar_floats(db, "Collection", "some_float", &float_values, &double_count); + size_t float_count = 0; + err = psr_database_read_scalar_floats(db, "Collection", "some_float", &float_values, &float_count); EXPECT_EQ(err, PSR_OK); - EXPECT_EQ(double_count, 0); + EXPECT_EQ(float_count, 0); EXPECT_EQ(float_values, nullptr); psr_database_close(db); @@ -237,20 +237,20 @@ TEST(DatabaseCApi, ReadVectorEmpty) { int64_t** int_vectors = nullptr; size_t* int_sizes = nullptr; - size_t int_count = 0; - auto err = psr_database_read_vector_integers(db, "Collection", "value_int", &int_vectors, &int_sizes, &int_count); + size_t integer_count = 0; + auto err = psr_database_read_vector_integers(db, "Collection", "value_int", &int_vectors, &int_sizes, &integer_count); EXPECT_EQ(err, PSR_OK); - EXPECT_EQ(int_count, 0); + EXPECT_EQ(integer_count, 0); EXPECT_EQ(int_vectors, nullptr); EXPECT_EQ(int_sizes, nullptr); double** double_vectors = nullptr; size_t* double_sizes = nullptr; - size_t double_count = 0; + size_t float_count = 0; err = - psr_database_read_vector_floats(db, "Collection", "value_float", &double_vectors, &double_sizes, &double_count); + psr_database_read_vector_floats(db, "Collection", "value_float", &double_vectors, &double_sizes, &float_count); EXPECT_EQ(err, PSR_OK); - EXPECT_EQ(double_count, 0); + EXPECT_EQ(float_count, 0); EXPECT_EQ(double_vectors, nullptr); EXPECT_EQ(double_sizes, nullptr); diff --git a/tests/test_c_api_element.cpp b/tests/test_c_api_element.cpp index d7d2038..6fc4f31 100644 --- a/tests/test_c_api_element.cpp +++ b/tests/test_c_api_element.cpp @@ -191,16 +191,16 @@ TEST(ElementCApi, StringFreeNull) { } TEST(ElementCApi, ArrayNullErrors) { - int64_t int_values[] = {1, 2, 3}; + int64_t integer_values[] = {1, 2, 3}; double float_values[] = {1.0, 2.0, 3.0}; const char* string_values[] = {"a", "b", "c"}; - EXPECT_EQ(psr_element_set_array_int(nullptr, "x", int_values, 3), PSR_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(psr_element_set_array_int(nullptr, "x", integer_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_float(nullptr, "x", float_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_string(nullptr, "x", string_values, 3), PSR_ERROR_INVALID_ARGUMENT); auto element = psr_element_create(); - EXPECT_EQ(psr_element_set_array_int(element, nullptr, int_values, 3), PSR_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(psr_element_set_array_int(element, nullptr, integer_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_float(element, nullptr, float_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_string(element, nullptr, string_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_int(element, "x", nullptr, 3), PSR_ERROR_INVALID_ARGUMENT); From ea7aa182b9331333504a41ec2e40c414bf6f3553 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:21:56 -0300 Subject: [PATCH 24/32] update --- tests/test_lua_runner.cpp | 4 ++-- tests/test_row_result.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_lua_runner.cpp b/tests/test_lua_runner.cpp index cc931e9..36afb25 100644 --- a/tests/test_lua_runner.cpp +++ b/tests/test_lua_runner.cpp @@ -128,8 +128,8 @@ TEST_F(LuaRunnerTest, ReadScalarFloatsFromLua) { lua.run(R"( local floats = db:read_scalar_floats("Collection", "some_float") assert(#floats == 2, "Expected 2 floats") - assert(floats[1] == 1.5, "First double should be 1.5") - assert(floats[2] == 2.5, "Second double should be 2.5") + assert(floats[1] == 1.5, "First float should be 1.5") + assert(floats[2] == 2.5, "Second float should be 2.5") )"); } diff --git a/tests/test_row_result.cpp b/tests/test_row_result.cpp index c9fc3ff..fc8452e 100644 --- a/tests/test_row_result.cpp +++ b/tests/test_row_result.cpp @@ -92,7 +92,7 @@ TEST(Row, GetIntWrongType) { } TEST(Row, GetFloatWrongType) { - psr::Row row(std::vector{std::string("not a double")}); + psr::Row row(std::vector{std::string("not a float")}); auto result = row.get_float(0); EXPECT_FALSE(result.has_value()); From b5d5f3a6618a4aff13974dd31178b333148d00e7 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:22:15 -0300 Subject: [PATCH 25/32] update --- include/psr/row.h | 2 +- src/database.cpp | 34 +++++++++++++++++----------------- src/row.cpp | 2 +- tests/test_row_result.cpp | 12 ++++++------ 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/psr/row.h b/include/psr/row.h index 5560717..e087540 100644 --- a/include/psr/row.h +++ b/include/psr/row.h @@ -22,7 +22,7 @@ class PSR_API Row { // Type-specific getters (return optionals for safe access) bool is_null(size_t index) const; - std::optional get_int(size_t index) const; + std::optional get_integer(size_t index) const; std::optional get_float(size_t index) const; std::optional get_string(size_t index) const; diff --git a/src/database.cpp b/src/database.cpp index d0d2f61..bcb20f0 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -603,11 +603,11 @@ int64_t Database::create_element(const std::string& collection, const Element& e // Look up the ID by label using direct SQL query auto lookup_sql = "SELECT id FROM " + fk.to_table + " WHERE label = ?"; auto lookup_result = execute(lookup_sql, {label}); - if (lookup_result.empty() || !lookup_result[0].get_int(0)) { + if (lookup_result.empty() || !lookup_result[0].get_integer(0)) { throw std::runtime_error("Failed to resolve label '" + label + "' to ID in table '" + fk.to_table + "'"); } - val = lookup_result[0].get_int(0).value(); + val = lookup_result[0].get_integer(0).value(); break; } } @@ -714,10 +714,10 @@ void Database::set_scalar_relation(const std::string& collection, // Look up the target ID by label auto lookup_sql = "SELECT id FROM " + to_table + " WHERE label = ?"; auto lookup_result = execute(lookup_sql, {to_label}); - if (lookup_result.empty() || !lookup_result[0].get_int(0)) { + if (lookup_result.empty() || !lookup_result[0].get_integer(0)) { throw std::runtime_error("Target element with label '" + to_label + "' not found in '" + to_table + "'"); } - auto to_id = lookup_result[0].get_int(0).value(); + auto to_id = lookup_result[0].get_integer(0).value(); // Update the source element auto update_sql = "UPDATE " + collection + " SET " + attribute + " = ? WHERE label = ?"; @@ -771,7 +771,7 @@ std::vector Database::read_scalar_integers(const std::string& collectio std::vector values; values.reserve(result.row_count()); for (size_t i = 0; i < result.row_count(); ++i) { - auto val = result[i].get_int(0); + auto val = result[i].get_integer(0); if (val) { values.push_back(*val); } @@ -817,7 +817,7 @@ Database::read_scalar_integers_by_id(const std::string& collection, const std::s if (result.empty()) { return std::nullopt; } - return result[0].get_int(0); + return result[0].get_integer(0); } std::optional @@ -852,8 +852,8 @@ std::vector> Database::read_vector_integers(const std::stri int64_t current_id = -1; for (size_t i = 0; i < result.row_count(); ++i) { - auto id = result[i].get_int(0); - auto val = result[i].get_int(1); + auto id = result[i].get_integer(0); + auto val = result[i].get_integer(1); if (!id) continue; @@ -880,7 +880,7 @@ std::vector> Database::read_vector_floats(const std::string& int64_t current_id = -1; for (size_t i = 0; i < result.row_count(); ++i) { - auto id = result[i].get_int(0); + auto id = result[i].get_integer(0); auto val = result[i].get_float(1); if (!id) @@ -908,7 +908,7 @@ std::vector> Database::read_vector_strings(const std::s int64_t current_id = -1; for (size_t i = 0; i < result.row_count(); ++i) { - auto id = result[i].get_int(0); + auto id = result[i].get_integer(0); auto val = result[i].get_string(1); if (!id) @@ -935,7 +935,7 @@ Database::read_vector_integers_by_id(const std::string& collection, const std::s std::vector values; values.reserve(result.row_count()); for (size_t i = 0; i < result.row_count(); ++i) { - auto val = result[i].get_int(0); + auto val = result[i].get_integer(0); if (val) { values.push_back(*val); } @@ -987,8 +987,8 @@ std::vector> Database::read_set_integers(const std::string& int64_t current_id = -1; for (size_t i = 0; i < result.row_count(); ++i) { - auto id = result[i].get_int(0); - auto val = result[i].get_int(1); + auto id = result[i].get_integer(0); + auto val = result[i].get_integer(1); if (!id) continue; @@ -1015,7 +1015,7 @@ std::vector> Database::read_set_floats(const std::string& co int64_t current_id = -1; for (size_t i = 0; i < result.row_count(); ++i) { - auto id = result[i].get_int(0); + auto id = result[i].get_integer(0); auto val = result[i].get_float(1); if (!id) @@ -1043,7 +1043,7 @@ std::vector> Database::read_set_strings(const std::stri int64_t current_id = -1; for (size_t i = 0; i < result.row_count(); ++i) { - auto id = result[i].get_int(0); + auto id = result[i].get_integer(0); auto val = result[i].get_string(1); if (!id) @@ -1070,7 +1070,7 @@ Database::read_set_integers_by_id(const std::string& collection, const std::stri std::vector values; values.reserve(result.row_count()); for (size_t i = 0; i < result.row_count(); ++i) { - auto val = result[i].get_int(0); + auto val = result[i].get_integer(0); if (val) { values.push_back(*val); } @@ -1119,7 +1119,7 @@ std::vector Database::read_element_ids(const std::string& collection) { std::vector ids; ids.reserve(result.row_count()); for (size_t i = 0; i < result.row_count(); ++i) { - auto val = result[i].get_int(0); + auto val = result[i].get_integer(0); if (val) { ids.push_back(*val); } diff --git a/src/row.cpp b/src/row.cpp index d16755a..fb816c3 100644 --- a/src/row.cpp +++ b/src/row.cpp @@ -28,7 +28,7 @@ bool Row::is_null(size_t index) const { return std::holds_alternative(values_[index]); } -std::optional Row::get_int(size_t index) const { +std::optional Row::get_integer(size_t index) const { if (index >= values_.size()) return std::nullopt; if (const auto* val = std::get_if(&values_[index])) { diff --git a/tests/test_row_result.cpp b/tests/test_row_result.cpp index fc8452e..351d897 100644 --- a/tests/test_row_result.cpp +++ b/tests/test_row_result.cpp @@ -57,10 +57,10 @@ TEST(Row, IsNullFalseForNonNull) { TEST(Row, GetIntOutOfBounds) { psr::Row row(std::vector{int64_t{42}}); - auto result = row.get_int(1); + auto result = row.get_integer(1); EXPECT_FALSE(result.has_value()); - result = row.get_int(100); + result = row.get_integer(100); EXPECT_FALSE(result.has_value()); } @@ -87,7 +87,7 @@ TEST(Row, GetStringOutOfBounds) { TEST(Row, GetIntWrongType) { psr::Row row(std::vector{std::string("not an int")}); - auto result = row.get_int(0); + auto result = row.get_integer(0); EXPECT_FALSE(result.has_value()); } @@ -108,7 +108,7 @@ TEST(Row, GetStringWrongType) { TEST(Row, GetIntFromNull) { psr::Row row(std::vector{nullptr}); - auto result = row.get_int(0); + auto result = row.get_integer(0); EXPECT_FALSE(result.has_value()); } @@ -217,7 +217,7 @@ TEST(Result, OperatorBracketValid) { psr::Result result(columns, std::move(rows)); const auto& row = result[0]; - EXPECT_EQ(row.get_int(0).value(), 42); + EXPECT_EQ(row.get_integer(0).value(), 42); } TEST(Result, MixedValueTypes) { @@ -231,7 +231,7 @@ TEST(Result, MixedValueTypes) { EXPECT_EQ(result.column_count(), 4u); const auto& row = result[0]; - EXPECT_EQ(row.get_int(0).value(), 42); + EXPECT_EQ(row.get_integer(0).value(), 42); EXPECT_DOUBLE_EQ(row.get_float(1).value(), 3.14); EXPECT_EQ(row.get_string(2).value(), "hello"); EXPECT_TRUE(row.is_null(3)); From a87283a4e00e7136e6d98e986af70b8a1569b30a Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:24:13 -0300 Subject: [PATCH 26/32] update --- bindings/julia/src/database_update.jl | 9 ++++++++- tests/test_c_api_database_read.cpp | 11 ++++++----- tests/test_lua_runner.cpp | 6 +++--- tests/test_row_result.cpp | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/bindings/julia/src/database_update.jl b/bindings/julia/src/database_update.jl index e1cb7c1..2cd2b0b 100644 --- a/bindings/julia/src/database_update.jl +++ b/bindings/julia/src/database_update.jl @@ -107,7 +107,14 @@ end function update_set_integers!(db::Database, collection::String, attribute::String, id::Int64, values::Vector{<:Integer}) integer_values = Int64[Int64(v) for v in values] - err = C.psr_database_update_set_integers(db.ptr, collection, attribute, id, integer_values, Csize_t(length(integer_values))) + err = C.psr_database_update_set_integers( + db.ptr, + collection, + attribute, + id, + integer_values, + Csize_t(length(integer_values)), + ) if err != C.PSR_OK throw(DatabaseException("Failed to update set integers '$collection.$attribute' for id $id")) end diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index 081c221..7fad73e 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -235,14 +235,15 @@ TEST(DatabaseCApi, ReadVectorEmpty) { psr_database_create_element(db, "Configuration", config); psr_element_destroy(config); - int64_t** int_vectors = nullptr; - size_t* int_sizes = nullptr; + int64_t** integer_vectors = nullptr; + size_t* integer_sizes = nullptr; size_t integer_count = 0; - auto err = psr_database_read_vector_integers(db, "Collection", "value_int", &int_vectors, &int_sizes, &integer_count); + auto err = + psr_database_read_vector_integers(db, "Collection", "value_int", &integer_vectors, &integer_sizes, &integer_count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(integer_count, 0); - EXPECT_EQ(int_vectors, nullptr); - EXPECT_EQ(int_sizes, nullptr); + EXPECT_EQ(integer_vectors, nullptr); + EXPECT_EQ(integer_sizes, nullptr); double** double_vectors = nullptr; size_t* double_sizes = nullptr; diff --git a/tests/test_lua_runner.cpp b/tests/test_lua_runner.cpp index 36afb25..15bcbfb 100644 --- a/tests/test_lua_runner.cpp +++ b/tests/test_lua_runner.cpp @@ -642,9 +642,9 @@ TEST_F(LuaRunnerTest, UpdateElementArraysIgnoredFromLua) { )"); // Verify from C++ side - auto int_value = db.read_scalar_integers_by_id("Collection", "some_integer", 1); - EXPECT_TRUE(int_value.has_value()); - EXPECT_EQ(*int_value, 999); + auto integer_value = db.read_scalar_integers_by_id("Collection", "some_integer", 1); + EXPECT_TRUE(integer_value.has_value()); + EXPECT_EQ(*integer_value, 999); auto vec_values = db.read_vector_integers_by_id("Collection", "value_int", 1); EXPECT_EQ(vec_values, (std::vector{1, 2, 3})); diff --git a/tests/test_row_result.cpp b/tests/test_row_result.cpp index 351d897..8fc62f6 100644 --- a/tests/test_row_result.cpp +++ b/tests/test_row_result.cpp @@ -221,7 +221,7 @@ TEST(Result, OperatorBracketValid) { } TEST(Result, MixedValueTypes) { - std::vector columns = {"int_col", "double_col", "string_col", "null_col"}; + std::vector columns = {"integer_col", "float_col", "string_col", "null_col"}; std::vector rows; rows.emplace_back(std::vector{int64_t{42}, 3.14, std::string("hello"), nullptr}); From e005059bdd434f75a7031adc4a72d0dbecd1a5b1 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:25:56 -0300 Subject: [PATCH 27/32] update --- bindings/dart/lib/src/database.dart | 12 ++++++------ bindings/dart/lib/src/ffi/bindings.dart | 20 ++++++++++---------- bindings/julia/src/c_api.jl | 8 ++++---- bindings/julia/src/database_read.jl | 12 ++++++------ bindings/julia/test/test_update.jl | 8 ++++---- include/psr/c/database.h | 4 ++-- src/c_api_database.cpp | 4 ++-- tests/test_c_api_database_delete.cpp | 8 ++++---- tests/test_c_api_database_read.cpp | 12 ++++++------ tests/test_c_api_database_update.cpp | 8 ++++---- tests/test_c_api_lua_runner.cpp | 4 ++-- tests/test_database_create.cpp | 12 ++++++------ tests/test_database_read.cpp | 4 ++-- tests/test_database_update.cpp | 12 ++++++------ tests/test_element.cpp | 4 ++-- tests/test_lua_runner.cpp | 14 +++++++------- 16 files changed, 73 insertions(+), 73 deletions(-) diff --git a/bindings/dart/lib/src/database.dart b/bindings/dart/lib/src/database.dart index c4d34e6..19adcb1 100644 --- a/bindings/dart/lib/src/database.dart +++ b/bindings/dart/lib/src/database.dart @@ -179,7 +179,7 @@ class Database { } final result = List.generate(count, (i) => outValues.value[i]); - bindings.psr_free_int_array(outValues.value); + bindings.psr_free_integer_array(outValues.value); return result; } finally { arena.releaseAll(); @@ -291,7 +291,7 @@ class Database { result.add(List.generate(size, (j) => outVectors.value[i][j])); } } - bindings.psr_free_int_vectors(outVectors.value, outSizes.value, count); + bindings.psr_free_integer_vectors(outVectors.value, outSizes.value, count); return result; } finally { arena.releaseAll(); @@ -423,7 +423,7 @@ class Database { result.add(List.generate(size, (j) => outSets.value[i][j])); } } - bindings.psr_free_int_vectors(outSets.value, outSizes.value, count); + bindings.psr_free_integer_vectors(outSets.value, outSizes.value, count); return result; } finally { arena.releaseAll(); @@ -648,7 +648,7 @@ class Database { } final result = List.generate(count, (i) => outValues.value[i]); - bindings.psr_free_int_array(outValues.value); + bindings.psr_free_integer_array(outValues.value); return result; } finally { arena.releaseAll(); @@ -755,7 +755,7 @@ class Database { } final result = List.generate(count, (i) => outValues.value[i]); - bindings.psr_free_int_array(outValues.value); + bindings.psr_free_integer_array(outValues.value); return result; } finally { arena.releaseAll(); @@ -860,7 +860,7 @@ class Database { } final result = List.generate(count, (i) => outIds.value[i]); - bindings.psr_free_int_array(outIds.value); + bindings.psr_free_integer_array(outIds.value); return result; } finally { arena.releaseAll(); diff --git a/bindings/dart/lib/src/ffi/bindings.dart b/bindings/dart/lib/src/ffi/bindings.dart index 91bcb63..7b1e01a 100644 --- a/bindings/dart/lib/src/ffi/bindings.dart +++ b/bindings/dart/lib/src/ffi/bindings.dart @@ -1073,17 +1073,17 @@ class PsrDatabaseBindings { int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int, ffi.Pointer>, int)>(); - void psr_free_int_array( + void psr_free_integer_array( ffi.Pointer values, ) { - return _psr_free_int_array( + return _psr_free_integer_array( values, ); } - late final _psr_free_int_arrayPtr = - _lookup)>>('psr_free_int_array'); - late final _psr_free_int_array = _psr_free_int_arrayPtr.asFunction)>(); + late final _psr_free_integer_arrayPtr = + _lookup)>>('psr_free_integer_array'); + late final _psr_free_integer_array = _psr_free_integer_arrayPtr.asFunction)>(); void psr_free_float_array( ffi.Pointer values, @@ -1113,22 +1113,22 @@ class PsrDatabaseBindings { late final _psr_free_string_array = _psr_free_string_arrayPtr.asFunction>, int)>(); - void psr_free_int_vectors( + void psr_free_integer_vectors( ffi.Pointer> vectors, ffi.Pointer sizes, int count, ) { - return _psr_free_int_vectors( + return _psr_free_integer_vectors( vectors, sizes, count, ); } - late final _psr_free_int_vectorsPtr = _lookup< + late final _psr_free_integer_vectorsPtr = _lookup< ffi.NativeFunction>, ffi.Pointer, ffi.Size)>>( - 'psr_free_int_vectors'); - late final _psr_free_int_vectors = _psr_free_int_vectorsPtr + 'psr_free_integer_vectors'); + late final _psr_free_integer_vectors = _psr_free_integer_vectorsPtr .asFunction>, ffi.Pointer, int)>(); void psr_free_float_vectors( diff --git a/bindings/julia/src/c_api.jl b/bindings/julia/src/c_api.jl index 6f7d099..7d345d0 100644 --- a/bindings/julia/src/c_api.jl +++ b/bindings/julia/src/c_api.jl @@ -246,8 +246,8 @@ function psr_database_update_set_strings(db, collection, attribute, id, values, @ccall libpsr_database_c.psr_database_update_set_strings(db::Ptr{psr_database_t}, collection::Ptr{Cchar}, attribute::Ptr{Cchar}, id::Int64, values::Ptr{Ptr{Cchar}}, count::Csize_t)::psr_error_t end -function psr_free_int_array(values) - @ccall libpsr_database_c.psr_free_int_array(values::Ptr{Int64})::Cvoid +function psr_free_integer_array(values) + @ccall libpsr_database_c.psr_free_integer_array(values::Ptr{Int64})::Cvoid end function psr_free_float_array(values) @@ -258,8 +258,8 @@ function psr_free_string_array(values, count) @ccall libpsr_database_c.psr_free_string_array(values::Ptr{Ptr{Cchar}}, count::Csize_t)::Cvoid end -function psr_free_int_vectors(vectors, sizes, count) - @ccall libpsr_database_c.psr_free_int_vectors(vectors::Ptr{Ptr{Int64}}, sizes::Ptr{Csize_t}, count::Csize_t)::Cvoid +function psr_free_integer_vectors(vectors, sizes, count) + @ccall libpsr_database_c.psr_free_integer_vectors(vectors::Ptr{Ptr{Int64}}, sizes::Ptr{Csize_t}, count::Csize_t)::Cvoid end function psr_free_float_vectors(vectors, sizes, count) diff --git a/bindings/julia/src/database_read.jl b/bindings/julia/src/database_read.jl index 0d70eeb..00f014b 100644 --- a/bindings/julia/src/database_read.jl +++ b/bindings/julia/src/database_read.jl @@ -41,7 +41,7 @@ function read_scalar_integers(db::Database, collection::String, attribute::Strin end result = unsafe_wrap(Array, out_values[], count) |> copy - C.psr_free_int_array(out_values[]) + C.psr_free_integer_array(out_values[]) return result end @@ -109,7 +109,7 @@ function read_vector_integers(db::Database, collection::String, attribute::Strin push!(result, copy(unsafe_wrap(Array, vectors_ptr[i], sizes_ptr[i]))) end end - C.psr_free_int_vectors(out_vectors[], out_sizes[], count) + C.psr_free_integer_vectors(out_vectors[], out_sizes[], count) return result end @@ -197,7 +197,7 @@ function read_set_integers(db::Database, collection::String, attribute::String) push!(result, copy(unsafe_wrap(Array, sets_ptr[i], sizes_ptr[i]))) end end - C.psr_free_int_vectors(out_sets[], out_sizes[], count) + C.psr_free_integer_vectors(out_sets[], out_sizes[], count) return result end @@ -326,7 +326,7 @@ function read_vector_integers_by_id(db::Database, collection::String, attribute: end result = unsafe_wrap(Array, out_values[], count) |> copy - C.psr_free_int_array(out_values[]) + C.psr_free_integer_array(out_values[]) return result end @@ -386,7 +386,7 @@ function read_set_integers_by_id(db::Database, collection::String, attribute::St end result = unsafe_wrap(Array, out_values[], count) |> copy - C.psr_free_int_array(out_values[]) + C.psr_free_integer_array(out_values[]) return result end @@ -444,7 +444,7 @@ function read_element_ids(db::Database, collection::String) end result = unsafe_wrap(Array, out_ids[], count) |> copy - C.psr_free_int_array(out_ids[]) + C.psr_free_integer_array(out_ids[]) return result end diff --git a/bindings/julia/test/test_update.jl b/bindings/julia/test/test_update.jl index 5e8da98..972cae2 100644 --- a/bindings/julia/test/test_update.jl +++ b/bindings/julia/test/test_update.jl @@ -45,8 +45,8 @@ include("fixture.jl") PSRDatabase.update_element!(db, "Configuration", Int64(1); integer_attribute = 500, float_attribute = 9.9) # Verify updates - int_value = PSRDatabase.read_scalar_integers_by_id(db, "Configuration", "integer_attribute", Int64(1)) - @test int_value == 500 + integer_value = PSRDatabase.read_scalar_integers_by_id(db, "Configuration", "integer_attribute", Int64(1)) + @test integer_value == 500 float_value = PSRDatabase.read_scalar_floats_by_id(db, "Configuration", "float_attribute", Int64(1)) @test float_value == 9.9 @@ -101,8 +101,8 @@ include("fixture.jl") PSRDatabase.update_element!(db, "Collection", Int64(1); some_integer = 999, value_int = [7, 8, 9]) # Verify scalar was updated - int_value = PSRDatabase.read_scalar_integers_by_id(db, "Collection", "some_integer", Int64(1)) - @test int_value == 999 + integer_value = PSRDatabase.read_scalar_integers_by_id(db, "Collection", "some_integer", Int64(1)) + @test integer_value == 999 # Verify vector was NOT updated (arrays ignored in update_element) vec_values = PSRDatabase.read_vector_integers_by_id(db, "Collection", "value_int", Int64(1)) diff --git a/include/psr/c/database.h b/include/psr/c/database.h index 1861180..d53cb94 100644 --- a/include/psr/c/database.h +++ b/include/psr/c/database.h @@ -279,12 +279,12 @@ PSR_C_API psr_error_t psr_database_update_set_strings(psr_database_t* db, size_t count); // Memory cleanup for read results -PSR_C_API void psr_free_int_array(int64_t* values); +PSR_C_API void psr_free_integer_array(int64_t* values); PSR_C_API void psr_free_float_array(double* values); PSR_C_API void psr_free_string_array(char** values, size_t count); // Memory cleanup for vector read results -PSR_C_API void psr_free_int_vectors(int64_t** vectors, size_t* sizes, size_t count); +PSR_C_API void psr_free_integer_vectors(int64_t** vectors, size_t* sizes, size_t count); PSR_C_API void psr_free_float_vectors(double** vectors, size_t* sizes, size_t count); PSR_C_API void psr_free_string_vectors(char*** vectors, size_t* sizes, size_t count); diff --git a/src/c_api_database.cpp b/src/c_api_database.cpp index 308d21c..012930a 100644 --- a/src/c_api_database.cpp +++ b/src/c_api_database.cpp @@ -311,7 +311,7 @@ PSR_C_API psr_error_t psr_database_read_scalar_strings(psr_database_t* db, } } -PSR_C_API void psr_free_int_array(int64_t* values) { +PSR_C_API void psr_free_integer_array(int64_t* values) { delete[] values; } @@ -399,7 +399,7 @@ PSR_C_API psr_error_t psr_database_read_vector_strings(psr_database_t* db, } } -PSR_C_API void psr_free_int_vectors(int64_t** vectors, size_t* sizes, size_t count) { +PSR_C_API void psr_free_integer_vectors(int64_t** vectors, size_t* sizes, size_t count) { free_vectors_impl(vectors, sizes, count); } diff --git a/tests/test_c_api_database_delete.cpp b/tests/test_c_api_database_delete.cpp index 3e57496..99d454a 100644 --- a/tests/test_c_api_database_delete.cpp +++ b/tests/test_c_api_database_delete.cpp @@ -22,7 +22,7 @@ TEST(DatabaseCApi, DeleteElementById) { auto err = psr_database_read_element_ids(db, "Configuration", &ids, &count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(count, 1); - psr_free_int_array(ids); + psr_free_integer_array(ids); // Delete element err = psr_database_delete_element_by_id(db, "Configuration", id); @@ -61,7 +61,7 @@ TEST(DatabaseCApi, DeleteElementByIdWithVectorData) { auto err = psr_database_read_vector_integers_by_id(db, "Collection", "value_int", id, &vec_values, &vec_count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(vec_count, 3); - psr_free_int_array(vec_values); + psr_free_integer_array(vec_values); // Delete element - CASCADE should delete vector rows too err = psr_database_delete_element_by_id(db, "Collection", id); @@ -159,7 +159,7 @@ TEST(DatabaseCApi, DeleteElementByIdNonExistent) { err = psr_database_read_element_ids(db, "Configuration", &ids, &count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(count, 1); - psr_free_int_array(ids); + psr_free_integer_array(ids); psr_database_close(db); } @@ -200,7 +200,7 @@ TEST(DatabaseCApi, DeleteElementByIdOtherElementsUnchanged) { EXPECT_EQ(count, 2); EXPECT_EQ(ids[0], id1); EXPECT_EQ(ids[1], id3); - psr_free_int_array(ids); + psr_free_integer_array(ids); // Verify first element unchanged int64_t val1; diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index 7fad73e..5824636 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -38,7 +38,7 @@ TEST(DatabaseCApi, ReadScalarIntegers) { EXPECT_EQ(values[0], 42); EXPECT_EQ(values[1], 100); - psr_free_int_array(values); + psr_free_integer_array(values); psr_database_close(db); } @@ -176,7 +176,7 @@ TEST(DatabaseCApi, ReadVectorIntegers) { EXPECT_EQ(vectors[1][0], 10); EXPECT_EQ(vectors[1][1], 20); - psr_free_int_vectors(vectors, sizes, count); + psr_free_integer_vectors(vectors, sizes, count); psr_database_close(db); } @@ -307,7 +307,7 @@ TEST(DatabaseCApi, ReadVectorOnlyReturnsElementsWithData) { EXPECT_EQ(vectors[1][0], 4); EXPECT_EQ(vectors[1][1], 5); - psr_free_int_vectors(vectors, sizes, count); + psr_free_integer_vectors(vectors, sizes, count); psr_database_close(db); } @@ -584,14 +584,14 @@ TEST(DatabaseCApi, ReadVectorIntegerById) { EXPECT_EQ(values[0], 1); EXPECT_EQ(values[1], 2); EXPECT_EQ(values[2], 3); - psr_free_int_array(values); + psr_free_integer_array(values); err = psr_database_read_vector_integers_by_id(db, "Collection", "value_int", id2, &values, &count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(count, 2); EXPECT_EQ(values[0], 10); EXPECT_EQ(values[1], 20); - psr_free_int_array(values); + psr_free_integer_array(values); psr_database_close(db); } @@ -773,7 +773,7 @@ TEST(DatabaseCApi, ReadElementIds) { EXPECT_EQ(ids[1], id2); EXPECT_EQ(ids[2], id3); - psr_free_int_array(ids); + psr_free_integer_array(ids); psr_database_close(db); } diff --git a/tests/test_c_api_database_update.cpp b/tests/test_c_api_database_update.cpp index de1eb37..96974c8 100644 --- a/tests/test_c_api_database_update.cpp +++ b/tests/test_c_api_database_update.cpp @@ -123,7 +123,7 @@ TEST(DatabaseCApi, UpdateVectorIntegers) { EXPECT_EQ(read_values[2], 30); EXPECT_EQ(read_values[3], 40); - psr_free_int_array(read_values); + psr_free_integer_array(read_values); psr_database_close(db); } @@ -332,12 +332,12 @@ TEST(DatabaseCApi, UpdateElementMultipleScalars) { psr_element_destroy(update); EXPECT_EQ(err, PSR_OK); - int64_t int_value; + int64_t integer_value; int has_value; - err = psr_database_read_scalar_integers_by_id(db, "Configuration", "integer_attribute", id, &int_value, &has_value); + err = psr_database_read_scalar_integers_by_id(db, "Configuration", "integer_attribute", id, &integer_value, &has_value); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(has_value, 1); - EXPECT_EQ(int_value, 100); + EXPECT_EQ(integer_value, 100); double double_value; err = psr_database_read_scalar_floats_by_id(db, "Configuration", "float_attribute", id, &double_value, &has_value); diff --git a/tests/test_c_api_lua_runner.cpp b/tests/test_c_api_lua_runner.cpp index 3d18004..df702da 100644 --- a/tests/test_c_api_lua_runner.cpp +++ b/tests/test_c_api_lua_runner.cpp @@ -92,7 +92,7 @@ TEST_F(LuaRunnerCApiTest, CreateElement) { EXPECT_EQ(read_result, PSR_OK); EXPECT_EQ(count, 1); EXPECT_EQ(values[0], 42); - psr_free_int_array(values); + psr_free_integer_array(values); psr_lua_runner_free(lua); psr_database_close(db); @@ -230,7 +230,7 @@ TEST_F(LuaRunnerCApiTest, CreateElementWithVectors) { EXPECT_EQ(vectors[0][0], 1); EXPECT_EQ(vectors[0][1], 2); EXPECT_EQ(vectors[0][2], 3); - psr_free_int_vectors(vectors, sizes, count); + psr_free_integer_vectors(vectors, sizes, count); psr_lua_runner_free(lua); psr_database_close(db); diff --git a/tests/test_database_create.cpp b/tests/test_database_create.cpp index 3e01111..b926799 100644 --- a/tests/test_database_create.cpp +++ b/tests/test_database_create.cpp @@ -48,9 +48,9 @@ TEST(Database, CreateElementWithVector) { EXPECT_EQ(labels.size(), 1); EXPECT_EQ(labels[0], "Item 1"); - auto int_vectors = db.read_vector_integers("Collection", "value_int"); - EXPECT_EQ(int_vectors.size(), 1); - EXPECT_EQ(int_vectors[0], (std::vector{1, 2, 3})); + auto integer_vectors = db.read_vector_integers("Collection", "value_int"); + EXPECT_EQ(integer_vectors.size(), 1); + EXPECT_EQ(integer_vectors[0], (std::vector{1, 2, 3})); auto float_vectors = db.read_vector_floats("Collection", "value_float"); EXPECT_EQ(float_vectors.size(), 1); @@ -76,9 +76,9 @@ TEST(Database, CreateElementWithVectorGroup) { EXPECT_EQ(id, 1); // Verify using public read APIs - auto int_vectors = db.read_vector_integers("Collection", "value_int"); - EXPECT_EQ(int_vectors.size(), 1); - EXPECT_EQ(int_vectors[0], (std::vector{10, 20, 30})); + auto integer_vectors = db.read_vector_integers("Collection", "value_int"); + EXPECT_EQ(integer_vectors.size(), 1); + EXPECT_EQ(integer_vectors[0], (std::vector{10, 20, 30})); auto float_vectors = db.read_vector_floats("Collection", "value_float"); EXPECT_EQ(float_vectors.size(), 1); diff --git a/tests/test_database_read.cpp b/tests/test_database_read.cpp index aed4964..90fba92 100644 --- a/tests/test_database_read.cpp +++ b/tests/test_database_read.cpp @@ -135,10 +135,10 @@ TEST(Database, ReadVectorEmpty) { db.create_element("Configuration", config); // No Collection elements created - auto int_vectors = db.read_vector_integers("Collection", "value_int"); + auto integer_vectors = db.read_vector_integers("Collection", "value_int"); auto double_vectors = db.read_vector_floats("Collection", "value_float"); - EXPECT_TRUE(int_vectors.empty()); + EXPECT_TRUE(integer_vectors.empty()); EXPECT_TRUE(double_vectors.empty()); } diff --git a/tests/test_database_update.cpp b/tests/test_database_update.cpp index 22e6b5e..e30d058 100644 --- a/tests/test_database_update.cpp +++ b/tests/test_database_update.cpp @@ -274,9 +274,9 @@ TEST(Database, UpdateElementMultipleScalars) { .set("string_attribute", std::string("world")); db.update_element("Configuration", id, update); - auto int_val = db.read_scalar_integers_by_id("Configuration", "integer_attribute", id); - EXPECT_TRUE(int_val.has_value()); - EXPECT_EQ(*int_val, 100); + auto integer_val = db.read_scalar_integers_by_id("Configuration", "integer_attribute", id); + EXPECT_TRUE(integer_val.has_value()); + EXPECT_EQ(*integer_val, 100); auto float_val = db.read_scalar_floats_by_id("Configuration", "float_attribute", id); EXPECT_TRUE(float_val.has_value()); @@ -337,9 +337,9 @@ TEST(Database, UpdateElementIgnoresArrays) { db.update_element("Collection", id, update); // Verify scalar was updated - auto int_val = db.read_scalar_integers_by_id("Collection", "some_integer", id); - EXPECT_TRUE(int_val.has_value()); - EXPECT_EQ(*int_val, 42); + auto integer_val = db.read_scalar_integers_by_id("Collection", "some_integer", id); + EXPECT_TRUE(integer_val.has_value()); + EXPECT_EQ(*integer_val, 42); // Verify vector was NOT updated (arrays should be ignored) auto vec = db.read_vector_integers_by_id("Collection", "value_int", id); diff --git a/tests/test_element.cpp b/tests/test_element.cpp index 32454e9..44bf7ea 100644 --- a/tests/test_element.cpp +++ b/tests/test_element.cpp @@ -240,10 +240,10 @@ TEST(Element, SetMultipleSameNameArrays) { TEST(Element, SetMixedScalarsAndArrays) { psr::Element element; element.set("label", std::string("Test")) - .set("int_value", int64_t{42}) + .set("integer_value", int64_t{42}) .set("double_value", 3.14) .set_null("null_value") - .set("int_array", std::vector{1, 2, 3}) + .set("integer_array", std::vector{1, 2, 3}) .set("double_array", std::vector{1.1, 2.2}) .set("string_array", std::vector{"a", "b", "c"}); diff --git a/tests/test_lua_runner.cpp b/tests/test_lua_runner.cpp index 15bcbfb..11058be 100644 --- a/tests/test_lua_runner.cpp +++ b/tests/test_lua_runner.cpp @@ -560,8 +560,8 @@ TEST_F(LuaRunnerTest, UpdateElementMultipleScalarsFromLua) { lua.run(R"( db:update_element("Collection", 1, { some_integer = 500, some_float = 9.9 }) - local int_val = db:read_scalar_integers_by_id("Collection", "some_integer", 1) - assert(int_val == 500, "Expected integer 500, got " .. tostring(int_val)) + local integer_val = db:read_scalar_integers_by_id("Collection", "some_integer", 1) + assert(integer_val == 500, "Expected integer 500, got " .. tostring(integer_val)) local float_val = db:read_scalar_floats_by_id("Collection", "some_float", 1) assert(float_val == 9.9, "Expected float 9.9, got " .. tostring(float_val)) @@ -572,9 +572,9 @@ TEST_F(LuaRunnerTest, UpdateElementMultipleScalarsFromLua) { )"); // Verify from C++ side - auto int_value = db.read_scalar_integers_by_id("Collection", "some_integer", 1); - EXPECT_TRUE(int_value.has_value()); - EXPECT_EQ(*int_value, 500); + auto integer_value = db.read_scalar_integers_by_id("Collection", "some_integer", 1); + EXPECT_TRUE(integer_value.has_value()); + EXPECT_EQ(*integer_value, 500); auto float_value = db.read_scalar_floats_by_id("Collection", "some_float", 1); EXPECT_TRUE(float_value.has_value()); @@ -630,8 +630,8 @@ TEST_F(LuaRunnerTest, UpdateElementArraysIgnoredFromLua) { db:update_element("Collection", 1, { some_integer = 999, value_int = {7, 8, 9} }) -- Verify scalar was updated - local int_val = db:read_scalar_integers_by_id("Collection", "some_integer", 1) - assert(int_val == 999, "Scalar should be updated to 999") + local integer_val = db:read_scalar_integers_by_id("Collection", "some_integer", 1) + assert(integer_val == 999, "Scalar should be updated to 999") -- Verify vector was NOT updated (arrays ignored in update_element) local vec = db:read_vector_integers_by_id("Collection", "value_int", 1) From da5a6648c1e48df0c59f7abbc736ae0d174e371f Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:26:26 -0300 Subject: [PATCH 28/32] update --- tests/test_c_api_database_read.cpp | 10 +++++----- tests/test_c_api_database_update.cpp | 6 +++--- tests/test_database_read.cpp | 4 ++-- tests/test_element.cpp | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index 5824636..e33f586 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -245,15 +245,15 @@ TEST(DatabaseCApi, ReadVectorEmpty) { EXPECT_EQ(integer_vectors, nullptr); EXPECT_EQ(integer_sizes, nullptr); - double** double_vectors = nullptr; - size_t* double_sizes = nullptr; + double** float_vectors = nullptr; + size_t* float_sizes = nullptr; size_t float_count = 0; err = - psr_database_read_vector_floats(db, "Collection", "value_float", &double_vectors, &double_sizes, &float_count); + psr_database_read_vector_floats(db, "Collection", "value_float", &float_vectors, &float_sizes, &float_count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(float_count, 0); - EXPECT_EQ(double_vectors, nullptr); - EXPECT_EQ(double_sizes, nullptr); + EXPECT_EQ(float_vectors, nullptr); + EXPECT_EQ(float_sizes, nullptr); psr_database_close(db); } diff --git a/tests/test_c_api_database_update.cpp b/tests/test_c_api_database_update.cpp index 96974c8..4076ef0 100644 --- a/tests/test_c_api_database_update.cpp +++ b/tests/test_c_api_database_update.cpp @@ -339,11 +339,11 @@ TEST(DatabaseCApi, UpdateElementMultipleScalars) { EXPECT_EQ(has_value, 1); EXPECT_EQ(integer_value, 100); - double double_value; - err = psr_database_read_scalar_floats_by_id(db, "Configuration", "float_attribute", id, &double_value, &has_value); + double float_value; + err = psr_database_read_scalar_floats_by_id(db, "Configuration", "float_attribute", id, &float_value, &has_value); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(has_value, 1); - EXPECT_DOUBLE_EQ(double_value, 2.71); + EXPECT_DOUBLE_EQ(float_value, 2.71); char* str_value = nullptr; err = psr_database_read_scalar_strings_by_id(db, "Configuration", "string_attribute", id, &str_value, &has_value); diff --git a/tests/test_database_read.cpp b/tests/test_database_read.cpp index 90fba92..9ba2228 100644 --- a/tests/test_database_read.cpp +++ b/tests/test_database_read.cpp @@ -136,10 +136,10 @@ TEST(Database, ReadVectorEmpty) { // No Collection elements created auto integer_vectors = db.read_vector_integers("Collection", "value_int"); - auto double_vectors = db.read_vector_floats("Collection", "value_float"); + auto float_vectors = db.read_vector_floats("Collection", "value_float"); EXPECT_TRUE(integer_vectors.empty()); - EXPECT_TRUE(double_vectors.empty()); + EXPECT_TRUE(float_vectors.empty()); } TEST(Database, ReadVectorOnlyReturnsElementsWithData) { diff --git a/tests/test_element.cpp b/tests/test_element.cpp index 44bf7ea..7bc70f5 100644 --- a/tests/test_element.cpp +++ b/tests/test_element.cpp @@ -241,10 +241,10 @@ TEST(Element, SetMixedScalarsAndArrays) { psr::Element element; element.set("label", std::string("Test")) .set("integer_value", int64_t{42}) - .set("double_value", 3.14) + .set("float_value", 3.14) .set_null("null_value") .set("integer_array", std::vector{1, 2, 3}) - .set("double_array", std::vector{1.1, 2.2}) + .set("float_array", std::vector{1.1, 2.2}) .set("string_array", std::vector{"a", "b", "c"}); EXPECT_EQ(element.scalars().size(), 4); From 1ec341ba640d0c11dc4137071fecac20481c07ce Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:26:48 -0300 Subject: [PATCH 29/32] update --- tests/test_c_api_database_read.cpp | 7 +++---- tests/test_c_api_database_update.cpp | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index e33f586..29c21ab 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -238,8 +238,8 @@ TEST(DatabaseCApi, ReadVectorEmpty) { int64_t** integer_vectors = nullptr; size_t* integer_sizes = nullptr; size_t integer_count = 0; - auto err = - psr_database_read_vector_integers(db, "Collection", "value_int", &integer_vectors, &integer_sizes, &integer_count); + auto err = psr_database_read_vector_integers( + db, "Collection", "value_int", &integer_vectors, &integer_sizes, &integer_count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(integer_count, 0); EXPECT_EQ(integer_vectors, nullptr); @@ -248,8 +248,7 @@ TEST(DatabaseCApi, ReadVectorEmpty) { double** float_vectors = nullptr; size_t* float_sizes = nullptr; size_t float_count = 0; - err = - psr_database_read_vector_floats(db, "Collection", "value_float", &float_vectors, &float_sizes, &float_count); + err = psr_database_read_vector_floats(db, "Collection", "value_float", &float_vectors, &float_sizes, &float_count); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(float_count, 0); EXPECT_EQ(float_vectors, nullptr); diff --git a/tests/test_c_api_database_update.cpp b/tests/test_c_api_database_update.cpp index 4076ef0..1c2671c 100644 --- a/tests/test_c_api_database_update.cpp +++ b/tests/test_c_api_database_update.cpp @@ -334,7 +334,8 @@ TEST(DatabaseCApi, UpdateElementMultipleScalars) { int64_t integer_value; int has_value; - err = psr_database_read_scalar_integers_by_id(db, "Configuration", "integer_attribute", id, &integer_value, &has_value); + err = psr_database_read_scalar_integers_by_id( + db, "Configuration", "integer_attribute", id, &integer_value, &has_value); EXPECT_EQ(err, PSR_OK); EXPECT_EQ(has_value, 1); EXPECT_EQ(integer_value, 100); From c3e3ea812712237adc47f664b15f2d1579ef148c Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:33:11 -0300 Subject: [PATCH 30/32] update --- bindings/dart/lib/src/element.dart | 2 +- bindings/dart/lib/src/ffi/bindings.dart | 4 +- bindings/julia/src/c_api.jl | 4 +- bindings/julia/src/element.jl | 2 +- bindings/julia/test/test_read.jl | 141 ++++++++++++++++++++++++ include/psr/c/element.h | 2 +- src/c_api_element.cpp | 2 +- tests/test_c_api_database_create.cpp | 2 +- tests/test_c_api_database_delete.cpp | 2 +- tests/test_c_api_database_read.cpp | 12 +- tests/test_c_api_database_update.cpp | 4 +- tests/test_c_api_element.cpp | 8 +- 12 files changed, 163 insertions(+), 22 deletions(-) diff --git a/bindings/dart/lib/src/element.dart b/bindings/dart/lib/src/element.dart index 7aa6d98..9c8eb51 100644 --- a/bindings/dart/lib/src/element.dart +++ b/bindings/dart/lib/src/element.dart @@ -159,7 +159,7 @@ class Element { for (var i = 0; i < values.length; i++) { arrayPtr[i] = values[i]; } - final error = bindings.psr_element_set_array_int( + final error = bindings.psr_element_set_array_integer( _ptr, namePtr.cast(), arrayPtr, diff --git a/bindings/dart/lib/src/ffi/bindings.dart b/bindings/dart/lib/src/ffi/bindings.dart index 7b1e01a..3535de4 100644 --- a/bindings/dart/lib/src/ffi/bindings.dart +++ b/bindings/dart/lib/src/ffi/bindings.dart @@ -1271,7 +1271,7 @@ class PsrDatabaseBindings { late final _psr_element_set_null = _psr_element_set_nullPtr.asFunction, ffi.Pointer)>(); - int psr_element_set_array_int( + int psr_element_set_array_integer( ffi.Pointer element, ffi.Pointer name, ffi.Pointer values, @@ -1288,7 +1288,7 @@ class PsrDatabaseBindings { late final _psr_element_set_array_intPtr = _lookup< ffi.NativeFunction< ffi.Int32 Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, - ffi.Int32)>>('psr_element_set_array_int'); + ffi.Int32)>>('psr_element_set_array_integer'); late final _psr_element_set_array_int = _psr_element_set_array_intPtr .asFunction, ffi.Pointer, ffi.Pointer, int)>(); diff --git a/bindings/julia/src/c_api.jl b/bindings/julia/src/c_api.jl index 7d345d0..6c2fb37 100644 --- a/bindings/julia/src/c_api.jl +++ b/bindings/julia/src/c_api.jl @@ -298,8 +298,8 @@ function psr_element_set_null(element, name) @ccall libpsr_database_c.psr_element_set_null(element::Ptr{psr_element_t}, name::Ptr{Cchar})::psr_error_t end -function psr_element_set_array_int(element, name, values, count) - @ccall libpsr_database_c.psr_element_set_array_int(element::Ptr{psr_element_t}, name::Ptr{Cchar}, values::Ptr{Int64}, count::Int32)::psr_error_t +function psr_element_set_array_integer(element, name, values, count) + @ccall libpsr_database_c.psr_element_set_array_integer(element::Ptr{psr_element_t}, name::Ptr{Cchar}, values::Ptr{Int64}, count::Int32)::psr_error_t end function psr_element_set_array_float(element, name, values, count) diff --git a/bindings/julia/src/element.jl b/bindings/julia/src/element.jl index 7819500..8c26738 100644 --- a/bindings/julia/src/element.jl +++ b/bindings/julia/src/element.jl @@ -46,7 +46,7 @@ end function Base.setindex!(el::Element, value::Vector{<:Integer}, name::String) cname = Base.cconvert(Cstring, name) integer_values = Int64[Int64(v) for v in value] - err = C.psr_element_set_array_int(el.ptr, cname, integer_values, Int32(length(integer_values))) + err = C.psr_element_set_array_integer(el.ptr, cname, integer_values, Int32(length(integer_values))) if err != C.PSR_OK error("Failed to set array value for '$name'") end diff --git a/bindings/julia/test/test_read.jl b/bindings/julia/test/test_read.jl index d919bac..c73de7c 100644 --- a/bindings/julia/test/test_read.jl +++ b/bindings/julia/test/test_read.jl @@ -667,6 +667,147 @@ include("fixture.jl") PSRDatabase.close!(db) end + + # ============================================================================ + # Generic read_by_id function tests + # ============================================================================ + + @testset "Generic Read by ID - Scalar Integer" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Config 1", integer_attribute = 42) + PSRDatabase.create_element!(db, "Configuration"; label = "Config 2", integer_attribute = 100) + + @test PSRDatabase.read_by_id(db, "Configuration", "integer_attribute", 1) == 42 + @test PSRDatabase.read_by_id(db, "Configuration", "integer_attribute", 2) == 100 + + PSRDatabase.close!(db) + end + + @testset "Generic Read by ID - Scalar Float" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Config 1", float_attribute = 3.14) + PSRDatabase.create_element!(db, "Configuration"; label = "Config 2", float_attribute = 2.71) + + @test PSRDatabase.read_by_id(db, "Configuration", "float_attribute", 1) == 3.14 + @test PSRDatabase.read_by_id(db, "Configuration", "float_attribute", 2) == 2.71 + + PSRDatabase.close!(db) + end + + @testset "Generic Read by ID - Scalar String" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Config 1", string_attribute = "hello") + PSRDatabase.create_element!(db, "Configuration"; label = "Config 2", string_attribute = "world") + + @test PSRDatabase.read_by_id(db, "Configuration", "string_attribute", 1) == "hello" + @test PSRDatabase.read_by_id(db, "Configuration", "string_attribute", 2) == "world" + + PSRDatabase.close!(db) + end + + @testset "Generic Read by ID - Vector Integer" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "collections.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Test Config") + PSRDatabase.create_element!(db, "Collection"; label = "Item 1", value_int = [1, 2, 3]) + PSRDatabase.create_element!(db, "Collection"; label = "Item 2", value_int = [10, 20]) + + @test PSRDatabase.read_by_id(db, "Collection", "value_int", 1) == [1, 2, 3] + @test PSRDatabase.read_by_id(db, "Collection", "value_int", 2) == [10, 20] + + PSRDatabase.close!(db) + end + + @testset "Generic Read by ID - Vector Float" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "collections.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Test Config") + PSRDatabase.create_element!(db, "Collection"; label = "Item 1", value_float = [1.5, 2.5, 3.5]) + PSRDatabase.create_element!(db, "Collection"; label = "Item 2", value_float = [10.5, 20.5]) + + @test PSRDatabase.read_by_id(db, "Collection", "value_float", 1) == [1.5, 2.5, 3.5] + @test PSRDatabase.read_by_id(db, "Collection", "value_float", 2) == [10.5, 20.5] + + PSRDatabase.close!(db) + end + + @testset "Generic Read by ID - Set String" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "collections.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Test Config") + PSRDatabase.create_element!(db, "Collection"; label = "Item 1", tag = ["important", "urgent"]) + PSRDatabase.create_element!(db, "Collection"; label = "Item 2", tag = ["review"]) + + result1 = PSRDatabase.read_by_id(db, "Collection", "tag", 1) + @test sort(result1) == ["important", "urgent"] + @test PSRDatabase.read_by_id(db, "Collection", "tag", 2) == ["review"] + + PSRDatabase.close!(db) + end + + @testset "Generic Read by ID - Scalar Not Found" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Config 1", integer_attribute = 42) + + # Scalar returns nothing for non-existent ID + @test PSRDatabase.read_by_id(db, "Configuration", "integer_attribute", 999) === nothing + @test PSRDatabase.read_by_id(db, "Configuration", "float_attribute", 999) === nothing + @test PSRDatabase.read_by_id(db, "Configuration", "string_attribute", 999) === nothing + + PSRDatabase.close!(db) + end + + @testset "Generic Read by ID - Vector Empty" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "collections.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + PSRDatabase.create_element!(db, "Configuration"; label = "Test Config") + PSRDatabase.create_element!(db, "Collection"; label = "Item 1") # No vector data + + # Vector returns empty array for element without data + @test PSRDatabase.read_by_id(db, "Collection", "value_int", 1) == Int64[] + + PSRDatabase.close!(db) + end + + @testset "Generic Read by ID - Invalid Collection" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + @test_throws PSRDatabase.DatabaseException PSRDatabase.read_by_id( + db, + "NonexistentCollection", + "label", + 1, + ) + + PSRDatabase.close!(db) + end + + @testset "Generic Read by ID - Invalid Attribute" begin + path_schema = joinpath(tests_path(), "schemas", "valid", "basic.sql") + db = PSRDatabase.from_schema(":memory:", path_schema) + + @test_throws PSRDatabase.DatabaseException PSRDatabase.read_by_id( + db, + "Configuration", + "nonexistent_attribute", + 1, + ) + + PSRDatabase.close!(db) + end end end diff --git a/include/psr/c/element.h b/include/psr/c/element.h index f74d2c5..97db417 100644 --- a/include/psr/c/element.h +++ b/include/psr/c/element.h @@ -22,7 +22,7 @@ PSR_C_API psr_error_t psr_element_set_string(psr_element_t* element, const char* PSR_C_API psr_error_t psr_element_set_null(psr_element_t* element, const char* name); // Array setters - C++ create_element routes these to vector/set tables based on schema -PSR_C_API psr_error_t psr_element_set_array_int(psr_element_t* element, +PSR_C_API psr_error_t psr_element_set_array_integer(psr_element_t* element, const char* name, const int64_t* values, int32_t count); diff --git a/src/c_api_element.cpp b/src/c_api_element.cpp index 8206177..a791773 100644 --- a/src/c_api_element.cpp +++ b/src/c_api_element.cpp @@ -57,7 +57,7 @@ PSR_C_API psr_error_t psr_element_set_null(psr_element_t* element, const char* n return PSR_OK; } -PSR_C_API psr_error_t psr_element_set_array_int(psr_element_t* element, +PSR_C_API psr_error_t psr_element_set_array_integer(psr_element_t* element, const char* name, const int64_t* values, int32_t count) { diff --git a/tests/test_c_api_database_create.cpp b/tests/test_c_api_database_create.cpp index 92aeebb..f6e3f8e 100644 --- a/tests/test_c_api_database_create.cpp +++ b/tests/test_c_api_database_create.cpp @@ -44,7 +44,7 @@ TEST(DatabaseCApi, CreateElementWithVector) { psr_element_set_string(element, "label", "Item 1"); int64_t values[] = {1, 2, 3}; - psr_element_set_array_int(element, "value_int", values, 3); + psr_element_set_array_integer(element, "value_int", values, 3); int64_t id = psr_database_create_element(db, "Collection", element); EXPECT_EQ(id, 1); diff --git a/tests/test_c_api_database_delete.cpp b/tests/test_c_api_database_delete.cpp index 99d454a..33cf7a8 100644 --- a/tests/test_c_api_database_delete.cpp +++ b/tests/test_c_api_database_delete.cpp @@ -51,7 +51,7 @@ TEST(DatabaseCApi, DeleteElementByIdWithVectorData) { auto e = psr_element_create(); psr_element_set_string(e, "label", "Item 1"); int64_t values[] = {1, 2, 3}; - psr_element_set_array_int(e, "value_int", values, 3); + psr_element_set_array_integer(e, "value_int", values, 3); int64_t id = psr_database_create_element(db, "Collection", e); psr_element_destroy(e); diff --git a/tests/test_c_api_database_read.cpp b/tests/test_c_api_database_read.cpp index 29c21ab..e2aa660 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -150,14 +150,14 @@ TEST(DatabaseCApi, ReadVectorIntegers) { auto e1 = psr_element_create(); psr_element_set_string(e1, "label", "Item 1"); int64_t values1[] = {1, 2, 3}; - psr_element_set_array_int(e1, "value_int", values1, 3); + psr_element_set_array_integer(e1, "value_int", values1, 3); psr_database_create_element(db, "Collection", e1); psr_element_destroy(e1); auto e2 = psr_element_create(); psr_element_set_string(e2, "label", "Item 2"); int64_t values2[] = {10, 20}; - psr_element_set_array_int(e2, "value_int", values2, 2); + psr_element_set_array_integer(e2, "value_int", values2, 2); psr_database_create_element(db, "Collection", e2); psr_element_destroy(e2); @@ -272,7 +272,7 @@ TEST(DatabaseCApi, ReadVectorOnlyReturnsElementsWithData) { auto e1 = psr_element_create(); psr_element_set_string(e1, "label", "Item 1"); int64_t values1[] = {1, 2, 3}; - psr_element_set_array_int(e1, "value_int", values1, 3); + psr_element_set_array_integer(e1, "value_int", values1, 3); psr_database_create_element(db, "Collection", e1); psr_element_destroy(e1); @@ -286,7 +286,7 @@ TEST(DatabaseCApi, ReadVectorOnlyReturnsElementsWithData) { auto e3 = psr_element_create(); psr_element_set_string(e3, "label", "Item 3"); int64_t values3[] = {4, 5}; - psr_element_set_array_int(e3, "value_int", values3, 2); + psr_element_set_array_integer(e3, "value_int", values3, 2); psr_database_create_element(db, "Collection", e3); psr_element_destroy(e3); @@ -563,14 +563,14 @@ TEST(DatabaseCApi, ReadVectorIntegerById) { auto e1 = psr_element_create(); psr_element_set_string(e1, "label", "Item 1"); int64_t values1[] = {1, 2, 3}; - psr_element_set_array_int(e1, "value_int", values1, 3); + psr_element_set_array_integer(e1, "value_int", values1, 3); int64_t id1 = psr_database_create_element(db, "Collection", e1); psr_element_destroy(e1); auto e2 = psr_element_create(); psr_element_set_string(e2, "label", "Item 2"); int64_t values2[] = {10, 20}; - psr_element_set_array_int(e2, "value_int", values2, 2); + psr_element_set_array_integer(e2, "value_int", values2, 2); int64_t id2 = psr_database_create_element(db, "Collection", e2); psr_element_destroy(e2); diff --git a/tests/test_c_api_database_update.cpp b/tests/test_c_api_database_update.cpp index 1c2671c..c7e4f75 100644 --- a/tests/test_c_api_database_update.cpp +++ b/tests/test_c_api_database_update.cpp @@ -105,7 +105,7 @@ TEST(DatabaseCApi, UpdateVectorIntegers) { auto e = psr_element_create(); psr_element_set_string(e, "label", "Item 1"); int64_t values1[] = {1, 2, 3}; - psr_element_set_array_int(e, "value_int", values1, 3); + psr_element_set_array_integer(e, "value_int", values1, 3); int64_t id = psr_database_create_element(db, "Collection", e); psr_element_destroy(e); @@ -175,7 +175,7 @@ TEST(DatabaseCApi, UpdateVectorToEmpty) { auto e = psr_element_create(); psr_element_set_string(e, "label", "Item 1"); int64_t values1[] = {1, 2, 3}; - psr_element_set_array_int(e, "value_int", values1, 3); + psr_element_set_array_integer(e, "value_int", values1, 3); int64_t id = psr_database_create_element(db, "Collection", e); psr_element_destroy(e); diff --git a/tests/test_c_api_element.cpp b/tests/test_c_api_element.cpp index 6fc4f31..3ca46b8 100644 --- a/tests/test_c_api_element.cpp +++ b/tests/test_c_api_element.cpp @@ -70,7 +70,7 @@ TEST(ElementCApi, SetArrayInt) { ASSERT_NE(element, nullptr); int64_t values[] = {10, 20, 30}; - EXPECT_EQ(psr_element_set_array_int(element, "counts", values, 3), PSR_OK); + EXPECT_EQ(psr_element_set_array_integer(element, "counts", values, 3), PSR_OK); EXPECT_EQ(psr_element_has_arrays(element), 1); EXPECT_EQ(psr_element_array_count(element), 1); @@ -195,15 +195,15 @@ TEST(ElementCApi, ArrayNullErrors) { double float_values[] = {1.0, 2.0, 3.0}; const char* string_values[] = {"a", "b", "c"}; - EXPECT_EQ(psr_element_set_array_int(nullptr, "x", integer_values, 3), PSR_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(psr_element_set_array_integer(nullptr, "x", integer_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_float(nullptr, "x", float_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_string(nullptr, "x", string_values, 3), PSR_ERROR_INVALID_ARGUMENT); auto element = psr_element_create(); - EXPECT_EQ(psr_element_set_array_int(element, nullptr, integer_values, 3), PSR_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(psr_element_set_array_integer(element, nullptr, integer_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_float(element, nullptr, float_values, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_string(element, nullptr, string_values, 3), PSR_ERROR_INVALID_ARGUMENT); - EXPECT_EQ(psr_element_set_array_int(element, "x", nullptr, 3), PSR_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(psr_element_set_array_integer(element, "x", nullptr, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_float(element, "x", nullptr, 3), PSR_ERROR_INVALID_ARGUMENT); EXPECT_EQ(psr_element_set_array_string(element, "x", nullptr, 3), PSR_ERROR_INVALID_ARGUMENT); psr_element_destroy(element); From bba25e3e5e10881aa29206b661a9ce04fbfe5074 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:34:41 -0300 Subject: [PATCH 31/32] update --- include/psr/c/element.h | 6 +++--- src/c_api_element.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/psr/c/element.h b/include/psr/c/element.h index 97db417..0772c5a 100644 --- a/include/psr/c/element.h +++ b/include/psr/c/element.h @@ -23,9 +23,9 @@ PSR_C_API psr_error_t psr_element_set_null(psr_element_t* element, const char* n // Array setters - C++ create_element routes these to vector/set tables based on schema PSR_C_API psr_error_t psr_element_set_array_integer(psr_element_t* element, - const char* name, - const int64_t* values, - int32_t count); + const char* name, + const int64_t* values, + int32_t count); PSR_C_API psr_error_t psr_element_set_array_float(psr_element_t* element, const char* name, const double* values, diff --git a/src/c_api_element.cpp b/src/c_api_element.cpp index a791773..774db6c 100644 --- a/src/c_api_element.cpp +++ b/src/c_api_element.cpp @@ -58,9 +58,9 @@ PSR_C_API psr_error_t psr_element_set_null(psr_element_t* element, const char* n } PSR_C_API psr_error_t psr_element_set_array_integer(psr_element_t* element, - const char* name, - const int64_t* values, - int32_t count) { + const char* name, + const int64_t* values, + int32_t count) { if (!element || !name || (!values && count > 0) || count < 0) { return PSR_ERROR_INVALID_ARGUMENT; } From a5c48dba181b5f914ecbd716be932c402407ae68 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Sun, 18 Jan 2026 19:35:10 -0300 Subject: [PATCH 32/32] update --- bindings/dart/lib/src/ffi/bindings.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/dart/lib/src/ffi/bindings.dart b/bindings/dart/lib/src/ffi/bindings.dart index 3535de4..8fa6f24 100644 --- a/bindings/dart/lib/src/ffi/bindings.dart +++ b/bindings/dart/lib/src/ffi/bindings.dart @@ -1277,7 +1277,7 @@ class PsrDatabaseBindings { ffi.Pointer values, int count, ) { - return _psr_element_set_array_int( + return _psr_element_set_array_integer( element, name, values, @@ -1285,11 +1285,11 @@ class PsrDatabaseBindings { ); } - late final _psr_element_set_array_intPtr = _lookup< + late final _psr_element_set_array_integerPtr = _lookup< ffi.NativeFunction< ffi.Int32 Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Int32)>>('psr_element_set_array_integer'); - late final _psr_element_set_array_int = _psr_element_set_array_intPtr + late final _psr_element_set_array_integer = _psr_element_set_array_integerPtr .asFunction, ffi.Pointer, ffi.Pointer, int)>(); int psr_element_set_array_float(