Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 - Support objects and new query functionality #2

Merged
merged 81 commits into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
68b623a
🔥 new design C.U.D. working
enzo418 Oct 5, 2022
2261b85
Retrieve is working
enzo418 Oct 8, 2022
49f8277
don't throw on missing composed
enzo418 Oct 8, 2022
a8d5f1d
🚀 select working as expected
enzo418 Oct 8, 2022
3e014c9
now it expands the composed properties
enzo418 Oct 8, 2022
1db3576
fixed property expression not working
enzo418 Oct 9, 2022
3f9c05d
Added subprops index by [] operator
enzo418 Oct 10, 2022
879c1f0
added missing json type
enzo418 Oct 10, 2022
9b1f468
query select, accept rvalue
enzo418 Oct 10, 2022
e5e97fe
removed unused member of composed prop
enzo418 Oct 10, 2022
8c548db
new object impl seems to work
enzo418 Oct 14, 2022
50f9e88
added array support
enzo418 Oct 14, 2022
1d12fa5
implemented new design guides
enzo418 Oct 16, 2022
be19298
🏃💨 defer add object
enzo418 Oct 16, 2022
a0deead
🚀 Snowflake everything
enzo418 Oct 17, 2022
bb1c577
call push in buffer to avoid data losses
enzo418 Oct 17, 2022
7913d45
addded .gitmodules
enzo418 Oct 17, 2022
8830603
added missing submodules
enzo418 Oct 17, 2022
1427191
fixed submodules
enzo418 Oct 17, 2022
105c36c
fixed object id wasn't an snowflake
enzo418 Oct 23, 2022
dd64ced
fixed select all properties
enzo418 Oct 23, 2022
44c566f
Merge branch 'dev' of https://github.com/enzo418/nolitedb into dev
enzo418 Oct 23, 2022
adaf738
fixed collections aggregations ddidn't work
enzo418 Oct 23, 2022
3167397
moved examples from main to single files
enzo418 Oct 23, 2022
1951d4a
updated cars example
enzo418 Oct 24, 2022
245f2b7
new join higher limits and new options
enzo418 Oct 25, 2022
f1b9907
fixed a bug where it didn't read correctly
enzo418 Oct 25, 2022
fdf0ae1
added timer to twitter example
enzo418 Oct 25, 2022
440ef3c
added profiling
enzo418 Oct 26, 2022
9b95e35
udapted docs
enzo418 Oct 26, 2022
2a31c83
updated readme
enzo418 Oct 26, 2022
c8b4c99
Merge pull request #1 from enzo418/new_join_64
enzo418 Oct 26, 2022
934e107
updated lrucache11 dependency
enzo418 Oct 26, 2022
f330fda
updated readme
enzo418 Oct 26, 2022
47a3de0
🚧 constexpr object detection
enzo418 Oct 26, 2022
9419015
added magic_enum as submodule
enzo418 Oct 26, 2022
67e5361
added example IsProperty
enzo418 Oct 27, 2022
7b65684
removed unused files
enzo418 Oct 28, 2022
1898e30
added option to suppress fields
enzo418 Oct 28, 2022
2b9c855
reworked suppress fields
enzo418 Oct 28, 2022
a191ff8
fixed bug on object
enzo418 Oct 28, 2022
97df963
lines replaced to use the Erase remove idiom
enzo418 Oct 28, 2022
74b35f1
object is now using forward list
enzo418 Oct 29, 2022
df0b89e
🎊 suppress fields that you did not even select
enzo418 Oct 29, 2022
97b358b
updated examples
enzo418 Oct 29, 2022
aa1b097
added cmake build type guard
enzo418 Nov 2, 2022
5882486
fixed memory errors
enzo418 Nov 3, 2022
16abc82
buffer data should be optional
enzo418 Nov 3, 2022
7f30aca
Warnings
enzo418 Nov 4, 2022
2eac938
removed problematic gcc flag
enzo418 Nov 4, 2022
46da9ec
fixed infinite loop if params is empty
enzo418 Nov 4, 2022
4ae4d7b
🤯 insert is x28 faster with WAL mode
enzo418 Nov 4, 2022
1b6893d
avoid name collision
enzo418 Nov 4, 2022
4986140
modified default buffer size
enzo418 Nov 4, 2022
003250d
store ids as strings
enzo418 Nov 4, 2022
6360cc9
run time cache and buffer with size configuration
enzo418 Nov 5, 2022
e725ded
added some status logging and memory configuration
enzo418 Nov 6, 2022
ecb3754
updated vendor version
enzo418 Nov 6, 2022
913ee3b
updated twitter example
enzo418 Nov 6, 2022
3111caf
added database tests and fixed a bug in execute
enzo418 Nov 7, 2022
e190e80
added query insert tests
enzo418 Nov 7, 2022
b0e3cb7
update readme
enzo418 Nov 8, 2022
2a5a1f8
update readme
enzo418 Nov 8, 2022
66a3205
update readme
enzo418 Nov 8, 2022
5cd1ce7
now you can select a collection instance
enzo418 Nov 8, 2022
c5741dd
added more select tests
enzo418 Nov 8, 2022
11c1e1a
added tests
enzo418 Nov 8, 2022
b20a81b
modified cars test
enzo418 Nov 8, 2022
fddd129
Merge branch 'dev' of https://github.com/enzo418/nolitedb into dev
enzo418 Nov 8, 2022
477d94f
removed "with" functions
enzo418 Nov 9, 2022
9f22a49
Added select by page tests
enzo418 Nov 9, 2022
4180768
added "Where" tests and fixed a bug
enzo418 Nov 9, 2022
b839c14
remove special chars from query and added tests
enzo418 Nov 9, 2022
c73c269
Fixed 2 bugs with tests
enzo418 Nov 10, 2022
7601800
added aggregate functions tests
enzo418 Nov 10, 2022
307615c
vacuum
enzo418 Nov 11, 2022
0072a0d
modified persona example
enzo418 Nov 11, 2022
ab75c6e
added update and remove tests
enzo418 Nov 13, 2022
a13beb2
updated test
enzo418 Nov 13, 2022
37a72be
replaced dot property syntax with [] access
enzo418 Nov 13, 2022
e4e28eb
now it allows to insert documents with id
enzo418 Nov 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
!src/
!src/**/
!tests/
!tests/**/
!.vscode/

!.gitignore
Expand All @@ -14,10 +15,21 @@
!*.h
!README.md
!CMakeLists.txt
!*.cmake

!vendor/
!vendor/*
!vendor/**/
!LICENSE*

!queries/
!queries/*.sql
!queries/*.sql

!*.plantuml
!docs/
!docs/**/
!docs/**/*.svg

!examples/
!examples/**/
!examples/**/*.sql
15 changes: 15 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[submodule "vendor/json"]
path = vendor/json
url = https://github.com/nlohmann/json
[submodule "vendor/lrucache11"]
path = vendor/lrucache11
url = https://github.com/enzo418/lrucache11
[submodule "vendor/spdlog"]
path = vendor/spdlog
url = https://github.com/gabime/spdlog
[submodule "vendor/googletest"]
path = vendor/googletest
url = https://github.com/google/googletest
[submodule "vendor/magic_enum"]
path = vendor/magic_enum
url = https://github.com/Neargye/magic_enum
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/build/noLiteDb",
"program": "${workspaceFolder}/build/twitter",
"args": [],
"preLaunchTask": "build",
"cwd": "${workspaceFolder}"
"cwd": "${workspaceFolder}/build"
},
{
"type": "lldb",
Expand All @@ -20,7 +20,7 @@
"program": "${workspaceFolder}/build/tests",
"args": [],
"preLaunchTask": "build",
"cwd": "${workspaceFolder}"
"cwd": "${workspaceFolder}/build"
}
]
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"options": {
"cwd": "${workspaceFolder}/build"
},
"command": "make -j4"
"command": "make -j"
}
]
}
122 changes: 92 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,115 @@ cmake_minimum_required(VERSION 3.22)

project(noLiteDb)

file(GLOB_RECURSE SOURCES src/*.cpp)
option(BUILD_EXAMPLES "Build examples" OFF)

# -------------------- CONFIGURATION ------------------- #

# A string used to differentiate between a user id and a document id.
set(NLDB_INTERNAL_ID "_id")

# REMOVE MAIN so we can don't need to compile the code again for the tests
list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)
option(NLDB_SHOW_ID_WARNING "Prints a warning if the requested is not the internal identifier." ON)

# ------------------ CONFIGURATION DEV ----------------- #
option(NLDB_DEBUG_CACHE_BUFFER "Shows cache hit/miss and buffer warnings" OFF)

# Set cmake cxx flags
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
option(NLDB_DEBUG_QUERY "Displays executed queries and human-readable aliases" OFF)

# clangd:
option(NLDB_PROFILE "Profile query execution time." OFF)

option(NLDB_SANITIZE_EXAMPLES "Use the compiler sanitizer in the examples." OFF)

# ----------------------- SOURCES ---------------------- #
file(GLOB_RECURSE SOURCES src/*.cpp)

# Set std version
# Note: I do it this way because otherwise export compile commands doesn't export it
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++20")

# clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include_directories(src/include)
include_directories(vendor/sqlite)
include_directories(vendor/logger/include)
include_directories(vendor/lrucache11)
include_directories(vendor/others)
if(NOT CMAKE_BUILD_TYPE )
# Compilation type
set(CMAKE_BUILD_TYPE DEBUG)
endif()

# --- YAMLCPP
# i thought to use yaml-cpp but doesn't have an easy way to get the data type
# and that was crucial for this library
include(Dependecy.cmake)

# --- json (nlohmann)
set(JSON_BuildTests OFF CACHE INTERNAL "")
set(JSON_Install OFF CACHE INTERNAL "")
add_subdirectory(vendor/json)
message(STATUS "NLDB dependencies: ${DEPENDENCY_LIST}")
message(STATUS "NLDB dependency libs: ${DEPENDENCY_LIBS}")
message(STATUS "NLDB dependency lib includes: ${DEPENDENCY_INCLUDE_DIR}")

# --- SQLITE library
add_library(c_sqllite3 vendor/sqlite/sqlite/sqlite3.c)
include_directories(src/include)
include_directories(src)

# --- Add nolitedb library
# --------------------- NOLITE --------------------- #
add_library(noLitedb_lb ${SOURCES})
target_link_libraries(noLitedb_lb c_sqllite3 nlohmann_json::nlohmann_json)

set(CMAKE_BUILD_TYPE DEBUG)
add_dependencies(noLitedb_lb ${DEPENDENCY_LIST})
target_include_directories(noLitedb_lb PUBLIC ${DEPENDENCY_INCLUDE_DIR} ${DEPENDENCY_INCLUDE_LIST})

# --- Add nolitedb executable
add_executable(noLiteDb src/main.cpp)
target_link_libraries(noLiteDb noLitedb_lb)
target_compile_options(noLitedb_lb PRIVATE -Wall -Wextra -Wpedantic -Werror)

# optional flags, e.g. -DNLDB_LIB_OPTIONAL_FLAGS:STRING="-w"
target_compile_options(noLitedb_lb PRIVATE "${NLDB_LIB_OPTIONAL_FLAGS}")

# in c++20 the expression Property == Property warns about something we don't care.
add_compile_options(-Wno-ambiguous-reversed-operator)

# boolean definitions
foreach(_VAR IN ITEMS
NLDB_DEBUG_QUERY
NLDB_DEBUG_CACHE_BUFFER
NLDB_SHOW_ID_WARNING
NLDB_PROFILE
)
if(${_VAR})
target_compile_definitions(noLitedb_lb PUBLIC "${_VAR}")
endif()
endforeach()

# valued definitions
target_compile_definitions(noLitedb_lb
PUBLIC
"NLDB_INTERNAL_ID=\"${NLDB_INTERNAL_ID}\""
)

target_link_libraries(noLitedb_lb PUBLIC ${DEPENDENCY_LIBS})
target_link_directories(noLitedb_lb PUBLIC ${DEPENDENCY_LIB_DIR})

# ------------------ NOLITE EXECUTABLE ----------------- #
if (NLDB_SANITIZE_EXAMPLES)
set(NLDB_SANITIZER_ARGS -fsanitize=address -fno-omit-frame-pointer)
message(STATUS "Using sanitizer options: ${NLDB_SANITIZER_ARGS}")
endif()

if(BUILD_EXAMPLES OR PROJECT_IS_TOP_LEVEL)
file(GLOB nldb_example_files
"examples/*.cpp")

foreach(filename ${nldb_example_files})
STRING(REGEX REPLACE
"([/\\][A-Za-z0-9_]+)+[/\\]([A-Za-z0-9_]+)\.c(pp)?"
"\\2" nldb_exec_name ${filename}) # get exec output name

add_executable(${nldb_exec_name} ${filename})
target_link_libraries(${nldb_exec_name} noLitedb_lb "-lz")

if(NLDB_SANITIZE_EXAMPLES)
target_compile_options(${nldb_exec_name} PRIVATE ${NLDB_SANITIZER_ARGS})
target_link_options(${nldb_exec_name} PRIVATE ${NLDB_SANITIZER_ARGS})
endif()
endforeach()
endif()

# --- TESTS
# ------------------------ TESTS ----------------------- #
add_subdirectory(vendor/googletest)
include_directories(vendor/googletest/googletest/include)

enable_testing()

file(GLOB TESTS_SRC tests/*.cpp)
file(GLOB_RECURSE TESTS_SRC tests/*.cpp)

add_executable(
tests
Expand All @@ -62,9 +124,9 @@ target_link_libraries(
)

if (CMAKE_BUILD_TYPE MATCHES "DEBUG")
add_definitions( -D LOGGER_MAX_LOG_LEVEL_PRINTED=6 ) # trace
add_definitions( -DLOGGER_MAX_LOG_LEVEL_PRINTED=6 ) # trace
else ()
add_definitions( -D LOGGER_MAX_LOG_LEVEL_PRINTED=1 ) # error
add_definitions( -DLOGGER_MAX_LOG_LEVEL_PRINTED=1 ) # error
endif()

include(GoogleTest)
Expand Down
64 changes: 64 additions & 0 deletions Dependecy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
include(ExternalProject)

set(DEPENDENCY_INSTALL_DIR ${PROJECT_BINARY_DIR}/install)
set(DEPENDENCY_INCLUDE_DIR ${DEPENDENCY_INSTALL_DIR}/include)
set(DEPENDENCY_LIB_DIR ${DEPENDENCY_INSTALL_DIR}/lib)

function(add_dep dep)
set(DEPENDENCY_LIST ${DEPENDENCY_LIST} ${dep} PARENT_SCOPE)
endfunction()

function(add_include include_dir)
set(DEPENDENCY_INCLUDE_LIST ${DEPENDENCY_INCLUDE_LIST} ${include_dir} PARENT_SCOPE)
endfunction()

function(add_lib lib)
set(DEPENDENCY_LIBS ${DEPENDENCY_LIBS} ${lib} PARENT_SCOPE)
endfunction(add_lib)

# ----------------------- SPDLOG ----------------------- #
ExternalProject_Add(
dep-spdlog
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/spdlog
UPDATE_COMMAND ""
PATCH_COMMAND ""
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${DEPENDENCY_INSTALL_DIR}
TEST_COMMAND ""
)

add_dep(dep-spdlog)
add_include(${CMAKE_CURRENT_SOURCE_DIR}/vendor/spdlog/include)
add_lib(spdlog)

# ----------------------- SQLITE3 ---------------------- #
add_library(xsqllite3 ${CMAKE_CURRENT_SOURCE_DIR}/vendor/sqlite/sqlite/sqlite3.c)

add_include(${CMAKE_CURRENT_SOURCE_DIR}/vendor/sqlite)
add_lib(xsqllite3)

# -------------------- NLOHMANN JSON ------------------- #
ExternalProject_Add(
dep-json
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/json
UPDATE_COMMAND ""
PATCH_COMMAND ""
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${DEPENDENCY_INSTALL_DIR}
-DNLOHMANN_JSON_INCLUDE_INSTALL_DIR=${DEPENDENCY_INSTALL_DIR}
-DJSON_Install=ON
-DJSON_BuildTests=OFF
TEST_COMMAND ""
)

add_dep(dep-json)
add_include(${CMAKE_CURRENT_SOURCE_DIR}/vendor/json/include)
# add_lib(nlohmann_json) # dependecy adds the .Targets file and handles the link_library

# --------------------- MAGIC ENUM --------------------- #
add_include(${CMAKE_CURRENT_SOURCE_DIR}/vendor/magic_enum/include)

# ---------------------- LRU CACHE --------------------- #
add_include(${CMAKE_CURRENT_SOURCE_DIR}/vendor/lrucache11/include)

# ----------------------- OTHERS ----------------------- #
add_include(${CMAKE_CURRENT_SOURCE_DIR}/vendor/others)
Loading