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 632c6f8..19adcb1 100644 --- a/bindings/dart/lib/src/database.dart +++ b/bindings/dart/lib/src/database.dart @@ -179,15 +179,15 @@ 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(); } } - /// Reads all double values for a scalar attribute from a collection. - List readScalarDoubles(String collection, String attribute) { + /// Reads all float values for a scalar attribute from a collection. + 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; @@ -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(); @@ -291,15 +291,15 @@ 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(); } } - /// Reads all double vectors for a vector attribute from a collection. - List> readVectorDoubles(String collection, String attribute) { + /// Reads all float vectors for a vector attribute from a collection. + 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; @@ -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(); @@ -423,15 +423,15 @@ 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(); } } - /// Reads all double sets for a set attribute from a collection. - List> readSetDoubles(String collection, String attribute) { + /// Reads all float sets for a set attribute from a collection. + 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; @@ -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(); @@ -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(), @@ -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) { @@ -648,15 +648,15 @@ 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(); } } - /// Reads double vector for a vector attribute by element ID. - List readVectorDoublesById(String collection, String attribute, int id) { + /// Reads float vector for a vector attribute by element 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; @@ -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(); @@ -755,15 +755,15 @@ 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(); } } - /// Reads double set for a set attribute by element ID. - List readSetDoublesById(String collection, String attribute, int id) { + /// Reads float set for a set attribute by element 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; @@ -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(); @@ -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(); @@ -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', }; @@ -988,13 +988,13 @@ class Database { } } - /// Updates a double scalar attribute value by element ID. - void updateScalarDouble(String collection, String attribute, int id, double value) { + /// Updates a float scalar attribute value by element ID. + 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(), @@ -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,8 +1062,8 @@ class Database { } } - /// Updates a double vector attribute by element ID (replaces entire vector). - void updateVectorDoubles(String collection, String attribute, int id, List values) { + /// Updates a float vector attribute by element ID (replaces entire vector). + 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(); @@ -1148,8 +1148,8 @@ class Database { } } - /// Updates a double set attribute by element ID (replaces entire set). - void updateSetDoubles(String collection, String attribute, int id, List values) { + /// Updates a float set attribute by element ID (replaces entire set). + 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..9c8eb51 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(); @@ -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); @@ -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, @@ -174,8 +174,8 @@ class Element { } } - /// Sets an array of doubles. - void setArrayDouble(String name, List values) { + /// Sets an array of floats. + void setArrayFloat(String name, List values) { _ensureNotDisposed(); final namePtr = name.toNativeUtf8(); final arrayPtr = malloc(values.length); @@ -184,14 +184,14 @@ class Element { 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); diff --git a/bindings/dart/lib/src/ffi/bindings.dart b/bindings/dart/lib/src/ffi/bindings.dart index 4dd3de3..8fa6f24 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)>(); @@ -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( @@ -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)>(); @@ -1073,29 +1073,29 @@ 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_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, @@ -1113,40 +1113,40 @@ 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_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, @@ -1271,13 +1271,13 @@ 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, int count, ) { - return _psr_element_set_array_int( + return _psr_element_set_array_integer( element, name, values, @@ -1285,20 +1285,20 @@ 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_int'); - late final _psr_element_set_array_int = _psr_element_set_array_intPtr + ffi.Int32)>>('psr_element_set_array_integer'); + late final _psr_element_set_array_integer = _psr_element_set_array_integerPtr .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( @@ -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/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..1c9962a 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,10 +249,10 @@ void main() { final lua = LuaRunner(db); try { lua.run(''' - local floats = db:read_scalar_doubles("Collection", "some_float") - assert(#floats == 2, "Expected 2 doubles") - assert(floats[1] == 1.5, "First double mismatch") - assert(floats[2] == 2.5, "Second double mismatch") + local floats = db:read_scalar_floats("Collection", "some_float") + assert(#floats == 2, "Expected 2 floats") + 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 8ce6d93..fa0493a 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(); } @@ -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'), @@ -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,8 +427,8 @@ void main() { }); }); - group('Read Scalar Doubles by ID', () { - test('reads double by specific element ID', () { + group('Read Scalar Floats by ID', () { + test('reads float by specific element ID', () { final db = Database.fromSchema( ':memory:', path.join(testsPath, 'schemas', 'valid', 'basic.sql'), @@ -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(); } @@ -500,8 +500,8 @@ void main() { }); }); - group('Read Vector Doubles by ID', () { - test('reads double vector by specific element ID', () { + group('Read Vector Floats by ID', () { + test('reads float vector by specific element ID', () { final db = Database.fromSchema( ':memory:', path.join(testsPath, 'schemas', 'valid', 'collections.sql'), @@ -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 { @@ -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'), @@ -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(); } @@ -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..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(); @@ -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/PSRDatabase.jl b/bindings/julia/src/PSRDatabase.jl index e468d24..0f50cf6 100644 --- a/bindings/julia/src/PSRDatabase.jl +++ b/bindings/julia/src/PSRDatabase.jl @@ -6,19 +6,20 @@ import .C 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 -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 # 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..6c2fb37 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() @@ -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) @@ -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) @@ -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,32 +238,32 @@ 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) @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_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) @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_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) @@ -298,12 +298,12 @@ 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_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.jl b/bindings/julia/src/database.jl index f84864d..5fa02e0 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) @@ -53,637 +33,3 @@ function close!(db::Database) 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 - -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 - 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_create.jl b/bindings/julia/src/database_create.jl new file mode 100644 index 0000000..cde9c24 --- /dev/null +++ b/bindings/julia/src/database_create.jl @@ -0,0 +1,33 @@ +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 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 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..00f014b --- /dev/null +++ b/bindings/julia/src/database_read.jl @@ -0,0 +1,537 @@ +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_integer_array(out_values[]) + return result +end + +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_floats(db.ptr, collection, attribute, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read scalar floats 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_float_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_integer_vectors(out_vectors[], out_sizes[], count) + return result +end + +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_floats(db.ptr, collection, attribute, out_vectors, out_sizes, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read vector floats 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_float_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_integer_vectors(out_sets[], out_sizes[], count) + return result +end + +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_floats(db.ptr, collection, attribute, out_sets, out_sizes, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read set floats 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_float_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_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_floats_by_id(db.ptr, collection, attribute, id, out_value, out_has_value) + if err != C.PSR_OK + throw(DatabaseException("Failed to read scalar float 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_integer_array(out_values[]) + return result +end + +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_floats_by_id(db.ptr, collection, attribute, id, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read vector floats 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_float_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_integer_array(out_values[]) + return result +end + +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_floats_by_id(db.ptr, collection, attribute, id, out_values, out_count) + if err != C.PSR_OK + throw(DatabaseException("Failed to read set floats 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_float_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_integer_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 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_FLOAT + 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 + 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_FLOAT + 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 + 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_FLOAT + 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 + throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) + end + 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_FLOAT + 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 + 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_FLOAT + 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 + 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_FLOAT + 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 + throw(DatabaseException("Unsupported data type for '$collection.$attribute'")) + end + else + throw(DatabaseException("Unsupported data structure for '$collection.$attribute'")) + end +end diff --git a/bindings/julia/src/database_update.jl b/bindings/julia/src/database_update.jl new file mode 100644 index 0000000..2cd2b0b --- /dev/null +++ b/bindings/julia/src/database_update.jl @@ -0,0 +1,156 @@ +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_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 float '$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}, +) + integer_values = Int64[Int64(v) for v in values] + err = C.psr_database_update_vector_integers( + db.ptr, + collection, + attribute, + id, + integer_values, + Csize_t(length(integer_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_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_floats( + db.ptr, + collection, + attribute, + id, + float_values, + Csize_t(length(float_values)), + ) + if err != C.PSR_OK + throw(DatabaseException("Failed to update vector floats '$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}) + 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 + return nothing +end + +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_floats( + db.ptr, + collection, + attribute, + id, + float_values, + Csize_t(length(float_values)), + ) + if err != C.PSR_OK + throw(DatabaseException("Failed to update set floats '$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/element.jl b/bindings/julia/src/element.jl index 2d5ed57..8c26738 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 @@ -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_integer(el.ptr, cname, integer_values, Int32(length(integer_values))) if err != C.PSR_OK error("Failed to set array value for '$name'") 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 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_element.jl b/bindings/julia/test/test_element.jl deleted file mode 100644 index bfa96f1..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_double"] = [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 b87a53b..9d1fead 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,10 +185,10 @@ include("fixture.jl") PSRDatabase.run!( lua, """ - local floats = db:read_scalar_doubles("Collection", "some_float") - assert(#floats == 2, "Expected 2 doubles") - assert(floats[1] == 1.5, "First double mismatch") - assert(floats[2] == 2.5, "Second double mismatch") + local floats = db:read_scalar_floats("Collection", "some_float") + assert(#floats == 2, "Expected 2 floats") + assert(floats[1] == 1.5, "First float mismatch") + assert(floats[2] == 2.5, "Second float mismatch") """, ) diff --git a/bindings/julia/test/test_read.jl b/bindings/julia/test/test_read.jl index 93b69fc..c73de7c 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 @@ -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 @@ -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", @@ -546,6 +546,268 @@ 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 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) + + 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 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]) + + 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 + + # ============================================================================ + # 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/bindings/julia/test/test_update.jl b/bindings/julia/test/test_update.jl index e9750aa..972cae2 100644 --- a/bindings/julia/test/test_update.jl +++ b/bindings/julia/test/test_update.jl @@ -45,10 +45,10 @@ 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_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 @@ -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)) @@ -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) @@ -272,25 +272,25 @@ 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) - value = PSRDatabase.read_scalar_doubles_by_id(db, "Configuration", "float_attribute", Int64(1)) + 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) - value = PSRDatabase.read_scalar_doubles_by_id(db, "Configuration", "float_attribute", Int64(1)) + 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) - value = PSRDatabase.read_scalar_doubles_by_id(db, "Configuration", "float_attribute", Int64(1)) + 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 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 c9a4ed8..d53cb94 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); @@ -80,11 +80,11 @@ 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, - const char* collection, - const char* attribute, - double** out_values, - 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); PSR_C_API psr_error_t psr_database_read_scalar_strings(psr_database_t* db, const char* collection, @@ -100,12 +100,12 @@ 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, - 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_floats(psr_database_t* db, + 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, @@ -122,12 +122,12 @@ 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, - 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_floats(psr_database_t* db, + 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, @@ -144,12 +144,12 @@ 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, - 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_floats_by_id(psr_database_t* db, + 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, @@ -166,12 +166,12 @@ 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, - 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_floats_by_id(psr_database_t* db, + 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, @@ -188,12 +188,12 @@ 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, - 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_floats_by_id(psr_database_t* db, + 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, @@ -222,11 +222,11 @@ 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, - const char* collection, - const char* attribute, - int64_t id, - double 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); PSR_C_API psr_error_t psr_database_update_scalar_string(psr_database_t* db, const char* collection, @@ -242,12 +242,12 @@ 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, - 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_floats(psr_database_t* db, + 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, @@ -264,12 +264,12 @@ 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, - 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_floats(psr_database_t* db, + 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, @@ -279,13 +279,13 @@ 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_double_array(double* 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_double_vectors(double** 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); #ifdef __cplusplus diff --git a/include/psr/c/element.h b/include/psr/c/element.h index 6ee7ef9..0772c5a 100644 --- a/include/psr/c/element.h +++ b/include/psr/c/element.h @@ -17,19 +17,19 @@ 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); // 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, - 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, - const char* name, - const double* values, - int32_t count); +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); +PSR_C_API psr_error_t psr_element_set_array_float(psr_element_t* element, + 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 f087085..c66a5ce 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); @@ -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, @@ -114,10 +114,10 @@ class PSR_API Database { const std::string& attribute, int64_t id, const std::vector& values); - void update_vector_doubles(const std::string& collection, - const std::string& attribute, - 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); void update_vector_strings(const std::string& collection, const std::string& attribute, int64_t id, @@ -128,10 +128,10 @@ class PSR_API Database { const std::string& attribute, int64_t id, const std::vector& values); - void update_set_doubles(const std::string& collection, - const std::string& attribute, - 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); void update_set_strings(const std::string& collection, const std::string& attribute, int64_t id, diff --git a/include/psr/row.h b/include/psr/row.h index ae25314..e087540 100644 --- a/include/psr/row.h +++ b/include/psr/row.h @@ -22,8 +22,8 @@ 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_integer(size_t index) const; + std::optional get_float(size_t index) const; std::optional get_string(size_t index) const; // Iterator support diff --git a/src/c_api_database.cpp b/src/c_api_database.cpp index f16ec0f..012930a 100644 --- a/src/c_api_database.cpp +++ b/src/c_api_database.cpp @@ -268,16 +268,16 @@ 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, - const char* collection, - const char* attribute, - double** out_values, - 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) { if (!db || !collection || !attribute || !out_values || !out_count) { 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; } @@ -311,11 +311,11 @@ 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; } -PSR_C_API void psr_free_double_array(double* values) { +PSR_C_API void psr_free_float_array(double* values) { delete[] values; } @@ -345,17 +345,17 @@ 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, - 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_floats(psr_database_t* db, + 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; } 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; } @@ -399,11 +399,11 @@ 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); } -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); } @@ -441,17 +441,17 @@ 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, - 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_floats(psr_database_t* db, + 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; } 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,17 +520,17 @@ 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, - 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_floats_by_id(psr_database_t* db, + 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; } 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,17 +588,17 @@ 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, - 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_floats_by_id(psr_database_t* db, + 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; } 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,17 +652,17 @@ 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, - 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_floats_by_id(psr_database_t* db, + 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; } 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; @@ -729,16 +729,16 @@ 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, - const char* collection, - const char* attribute, - int64_t id, - double 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) { if (!db || !collection || !attribute) { 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; @@ -781,18 +781,18 @@ 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, - 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_floats(psr_database_t* db, + 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; } 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,18 +841,18 @@ 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, - 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_floats(psr_database_t* db, + 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; } 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; @@ -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/src/c_api_element.cpp b/src/c_api_element.cpp index 23ea755..774db6c 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; } @@ -57,10 +57,10 @@ 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, - const char* name, - const int64_t* values, - int32_t count) { +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) { if (!element || !name || (!values && count > 0) || count < 0) { return PSR_ERROR_INVALID_ARGUMENT; } @@ -69,10 +69,10 @@ 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, - const char* name, - const double* 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) { if (!element || !name || (!values && count > 0) || count < 0) { return PSR_ERROR_INVALID_ARGUMENT; } diff --git a/src/database.cpp b/src/database.cpp index a0d1a5a..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); } @@ -779,14 +779,14 @@ 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); 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); } @@ -817,18 +817,18 @@ 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 -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}); if (result.empty()) { return std::nullopt; } - return result[0].get_double(0); + return result[0].get_float(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; @@ -870,8 +870,8 @@ std::vector> Database::read_vector_integers(const std::stri return vectors; } -std::vector> Database::read_vector_doubles(const std::string& collection, - const std::string& attribute) { +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"; auto result = execute(sql); @@ -880,8 +880,8 @@ std::vector> Database::read_vector_doubles(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_double(1); + auto id = result[i].get_integer(0); + auto val = result[i].get_float(1); if (!id) continue; @@ -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); } @@ -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}); @@ -952,7 +952,7 @@ Database::read_vector_doubles_by_id(const std::string& collection, const std::st 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); } @@ -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; @@ -1005,8 +1005,8 @@ std::vector> Database::read_set_integers(const std::string& return sets; } -std::vector> Database::read_set_doubles(const std::string& collection, - const std::string& attribute) { +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"; auto result = execute(sql); @@ -1015,8 +1015,8 @@ std::vector> Database::read_set_doubles(const std::string& c 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_double(1); + auto id = result[i].get_integer(0); + auto val = result[i].get_float(1); if (!id) continue; @@ -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); } @@ -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}); @@ -1087,7 +1087,7 @@ Database::read_set_doubles_by_id(const std::string& collection, const std::strin 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); } @@ -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); } @@ -1141,10 +1141,10 @@ 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, - const std::string& attribute, - int64_t id, - double value) { +void Database::update_scalar_float(const std::string& collection, + 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); @@ -1198,10 +1198,10 @@ 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, - const std::string& attribute, - int64_t id, - const std::vector& values) { +void Database::update_vector_floats(const std::string& collection, + 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"); @@ -1284,10 +1284,10 @@ 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, - const std::string& attribute, - int64_t id, - const std::vector& values) { +void Database::update_set_floats(const std::string& collection, + 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 34bb552..032cbd3 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, - const std::string& collection, - const std::string& attribute, - sol::this_state s) { + 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, - const std::string& collection, - const std::string& attribute, - sol::this_state s) { + 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, - const std::string& collection, - const std::string& attribute, - int64_t id, - sol::this_state s) { + 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, - const std::string& collection, - const std::string& attribute, - int64_t id, - sol::this_state s) { + 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, - const std::string& collection, - const std::string& attribute, - int64_t id, - sol::this_state s) { + 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/src/row.cpp b/src/row.cpp index a8db9b5..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])) { @@ -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])) { diff --git a/tests/test_c_api_database_create.cpp b/tests/test_c_api_database_create.cpp index b7d3bec..f6e3f8e 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); @@ -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 3e57496..33cf7a8 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); @@ -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); @@ -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 ba0d7a2..e2aa660 100644 --- a/tests/test_c_api_database_read.cpp +++ b/tests/test_c_api_database_read.cpp @@ -38,11 +38,11 @@ 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); } -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); @@ -50,26 +50,26 @@ TEST(DatabaseCApi, ReadScalarDoubles) { 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); 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); 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); } @@ -115,19 +115,19 @@ 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* double_values = nullptr; - size_t double_count = 0; - err = psr_database_read_scalar_doubles(db, "Collection", "some_float", &double_values, &double_count); + double* float_values = nullptr; + 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(double_values, nullptr); + EXPECT_EQ(float_count, 0); + EXPECT_EQ(float_values, nullptr); psr_database_close(db); } @@ -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); @@ -176,11 +176,11 @@ 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); } -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); @@ -194,21 +194,21 @@ TEST(DatabaseCApi, ReadVectorDoubles) { 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); 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); @@ -220,7 +220,7 @@ TEST(DatabaseCApi, ReadVectorDoubles) { 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); } @@ -235,24 +235,24 @@ TEST(DatabaseCApi, ReadVectorEmpty) { psr_database_create_element(db, "Configuration", config); psr_element_destroy(config); - 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); + 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); EXPECT_EQ(err, PSR_OK); - EXPECT_EQ(int_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; - err = psr_database_read_vector_doubles( - db, "Collection", "value_float", &double_vectors, &double_sizes, &double_count); + EXPECT_EQ(integer_count, 0); + EXPECT_EQ(integer_vectors, nullptr); + EXPECT_EQ(integer_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", &float_vectors, &float_sizes, &float_count); EXPECT_EQ(err, PSR_OK); - EXPECT_EQ(double_count, 0); - EXPECT_EQ(double_vectors, nullptr); - EXPECT_EQ(double_sizes, nullptr); + EXPECT_EQ(float_count, 0); + EXPECT_EQ(float_vectors, nullptr); + EXPECT_EQ(float_sizes, nullptr); psr_database_close(db); } @@ -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); @@ -306,7 +306,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); } @@ -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,13 +483,13 @@ 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); 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); @@ -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); @@ -583,19 +583,19 @@ 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); } -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,13 +609,13 @@ 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); 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); @@ -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); } @@ -772,7 +772,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); } @@ -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); } @@ -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..c7e4f75 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,16 +44,16 @@ 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; 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); @@ -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); @@ -123,11 +123,11 @@ 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); } -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); @@ -141,23 +141,23 @@ TEST(DatabaseCApi, UpdateVectorDoubles) { 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); 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); EXPECT_DOUBLE_EQ(read_values[1], 20.5); - psr_free_double_array(read_values); + psr_free_float_array(read_values); psr_database_close(db); } @@ -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); @@ -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,24 +326,25 @@ 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); 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_doubles_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); @@ -464,18 +465,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); @@ -546,20 +547,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 +608,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_c_api_element.cpp b/tests/test_c_api_element.cpp index 6c73b41..3ca46b8 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); @@ -70,19 +70,19 @@ 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); 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); @@ -191,20 +191,20 @@ TEST(ElementCApi, StringFreeNull) { } TEST(ElementCApi, ArrayNullErrors) { - int64_t int_values[] = {1, 2, 3}; - double double_values[] = {1.0, 2.0, 3.0}; + 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_double(nullptr, "x", double_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, 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_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_double(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); } 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 94667d7..b926799 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"); @@ -48,11 +48,11 @@ 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_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})); } @@ -76,11 +76,11 @@ 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_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..7d4ae9d 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); } // ============================================================================ @@ -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) { @@ -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); } // ============================================================================ @@ -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 d84b4e1..9ba2228 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})); @@ -135,11 +135,11 @@ TEST(Database, ReadVectorEmpty) { db.create_element("Configuration", config); // 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 integer_vectors = db.read_vector_integers("Collection", "value_int"); + auto float_vectors = db.read_vector_floats("Collection", "value_float"); - EXPECT_TRUE(int_vectors.empty()); - EXPECT_TRUE(double_vectors.empty()); + EXPECT_TRUE(integer_vectors.empty()); + EXPECT_TRUE(float_vectors.empty()); } TEST(Database, ReadVectorOnlyReturnsElementsWithData) { @@ -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; @@ -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); @@ -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}); @@ -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..e30d058 100644 --- a/tests/test_database_update.cpp +++ b/tests/test_database_update.cpp @@ -22,16 +22,16 @@ 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_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})); } @@ -274,11 +274,11 @@ 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_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); @@ -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 e0058e4..7bc70f5 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}); @@ -240,11 +240,11 @@ TEST(Element, SetMultipleSameNameArrays) { TEST(Element, SetMixedScalarsAndArrays) { psr::Element element; element.set("label", std::string("Test")) - .set("int_value", int64_t{42}) - .set("double_value", 3.14) + .set("integer_value", int64_t{42}) + .set("float_value", 3.14) .set_null("null_value") - .set("int_array", std::vector{1, 2, 3}) - .set("double_array", std::vector{1.1, 2.2}) + .set("integer_array", std::vector{1, 2, 3}) + .set("float_array", std::vector{1.1, 2.2}) .set("string_array", std::vector{"a", "b", "c"}); EXPECT_EQ(element.scalars().size(), 4); diff --git a/tests/test_lua_runner.cpp b/tests/test_lua_runner.cpp index 3f4c7c9..11058be 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 float should be 1.5") + assert(floats[2] == 2.5, "Second float 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") @@ -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")); @@ -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)) )"; @@ -560,10 +560,10 @@ 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_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 @@ -572,11 +572,11 @@ 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_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); } @@ -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) @@ -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})); @@ -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..8fc62f6 100644 --- a/tests/test_row_result.cpp +++ b/tests/test_row_result.cpp @@ -57,20 +57,20 @@ 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()); } -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()); } @@ -87,14 +87,14 @@ 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()); } -TEST(Row, GetDoubleWrongType) { - psr::Row row(std::vector{std::string("not a double")}); +TEST(Row, GetFloatWrongType) { + psr::Row row(std::vector{std::string("not a float")}); - auto result = row.get_double(0); + auto result = row.get_float(0); EXPECT_FALSE(result.has_value()); } @@ -108,14 +108,14 @@ 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()); } -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()); } @@ -217,11 +217,11 @@ 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) { - 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}); @@ -231,8 +231,8 @@ TEST(Result, MixedValueTypes) { EXPECT_EQ(result.column_count(), 4u); const auto& row = result[0]; - EXPECT_EQ(row.get_int(0).value(), 42); - EXPECT_DOUBLE_EQ(row.get_double(1).value(), 3.14); + 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)); } @@ -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 }