Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaraslaut committed Dec 13, 2024
1 parent cbd033f commit 0ee3128
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 6 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Docs

on:
merge_group:
push:
branches:
- master
pull_request:
branches:
- master


concurrency:
group: docs-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write
jobs:
create_documentation:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: update apt
run: sudo apt -q update
- name: install dependencies
run: sudo apt install -y cmake ninja-build catch2 unixodbc-dev sqlite3 libsqlite3-dev libsqliteodbc valgrind uuid-dev g++-14 doxygen
- name: cmake configure
run: cmake --preset linux-gcc-release
- name: build
run: cmake --build --preset linux-gcc-release --target doc

- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: html
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ vcpkg_installed/
CMakeSettings.json
compile_commands.json
*.sqlite
/html/
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ add_subdirectory(src/tools)
enable_testing()
add_subdirectory(src/tests)
add_subdirectory(src/benchmark)
add_subdirectory(docs)
50 changes: 50 additions & 0 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
find_package(Doxygen)

if(DOXYGEN_FOUND)
message(STATUS "Doxygen found: ${DOXYGEN_EXECUTABLE}")

FetchContent_Declare(
doxygen-awesome-css
GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css.git
GIT_TAG v2.3.4
)

FetchContent_MakeAvailable(doxygen-awesome-css)

# Halide-specific Doxygen options
set(DOXYGEN_ALPHABETICAL_INDEX NO)
set(DOXYGEN_BUILTIN_STL_SUPPORT YES)
set(DOXYGEN_CASE_SENSE_NAMES NO)
set(DOXYGEN_CLASS_DIAGRAMS NO)
set(DOXYGEN_EXCLUDE bin)
set(DOXYGEN_EXTRACT_ALL NO)
set(DOXYGEN_EXTRACT_LOCAL_CLASSES NO)
set(DOXYGEN_FILE_PATTERNS *.hpp)
set(DOXYGEN_GENERATE_TREEVIEW YES)
set(DOXYGEN_HIDE_UNDOC_CLASSES YES)
set(DOXYGEN_HIDE_FRIEND_COMPOUNDS YES)
set(DOXYGEN_HIDE_IN_BODY_DOCS YES)
set(DOXYGEN_MARKDOWN_ID_STYLE GITHUB)
set(DOXYGEN_QT_AUTOBRIEF YES)
set(DOXYGEN_QUIET YES)
set(DOXYGEN_RECURSIVE YES)
set(DOXYGEN_REFERENCED_BY_RELATION YES)
set(DOXYGEN_REFERENCES_RELATION YES)
set(DOXYGEN_SORT_BY_SCOPE_NAME YES)
set(DOXYGEN_SORT_MEMBER_DOCS NO)
set(DOXYGEN_SOURCE_BROWSER YES)
set(DOXYGEN_STRIP_CODE_COMMENTS NO)
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "${PROJECT_SOURCE_DIR}/README.md")
set(DOXYGEN_HTML_EXTRA_STYLESHEET "${CMAKE_BINARY_DIR}/_deps/doxygen-awesome-css-src/doxygen-awesome.css")
set(DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}")
set(DOXYGEN_EXCLUDE_SYMBOLS "detail,detail::*,std,std::*,benchmark,test")

doxygen_add_docs(doc
"${PROJECT_SOURCE_DIR}/src;${PROJECT_SOURCE_DIR}/README.md;${PROJECT_SOURCE_DIR}/docs/usage.md"
ALL
COMMENT "Generate HTML documentation")


else()
message(WARNING "Doxygen not found, not generating documentation")

Check warning on line 49 in docs/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / Windows

Doxygen not found, not generating documentation
endif()
1 change: 1 addition & 0 deletions docs/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
www.lightweight.org
48 changes: 48 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Examples

# Configure connection to the database

To connect to the database you need to provide connection string that library uses to establish connection and you can check if it alive in the following way
```c
SqlConnection::SetDefaultConnectionString(SqlConnectionString {
.value = std::format("DRIVER=SQLite3;Database={}", SqlConnectionString::SanitizePwd("Database.sqlite")) });

auto sqlConnection = SqlConnection();
if (!sqlConnection.IsAlive())
{
std::println("Failed to connect to the database: {}",
SqlErrorInfo::fromConnectionHandle(sqlConnection.NativeHandle()));
std::abort();
}
```
# Sql Query
You can directly make a call to the database using `ExecuteDirect` function, for example
```c
auto stmt = SqlStatement {};
stmt.ExecuteDirect(R"("SELECT "a", "b", "c" FROM "That" ORDER BY "That"."b" DESC)"));
while (stmt.FetchRow())
{
auto a = stmt.GetColumn<int>(1);
auto b = stmt.GetColumn<int>(2);
auto c = stmt.GetColumn<int>(3);
std::println("{}|{}|{}", a, b,c);
}
```

Or you can constuct statement using `SqlQueryBuilder` for different databases
```c
auto sqliteQueryBuilder = SqlQueryBuilder(formatter);
auto const sqlQuery = sqliteQueryBuilder.FromTable("That")
.Select()
.Fields("a", "b")
.Field("c")
.OrderBy(SqlQualifiedTableColumnName { .tableName = "That", .columnName = "b" },
SqlResultOrdering::DESCENDING)
.All()

```
For more info see `SqlQuery` and `SqlQueryFormatter` documentation
16 changes: 10 additions & 6 deletions src/Lightweight/SqlQuery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ struct [[nodiscard]] SqlLastInsertIdQuery
}
};

// API Entry point for building SQL queries.
/////////////////////////////////////////////////
/// API Entry point for building SQL queries.
/////////////////////////////////////////////////
class [[nodiscard]] SqlQueryBuilder final
{
public:
Expand All @@ -34,11 +36,13 @@ class [[nodiscard]] SqlQueryBuilder final
// Constructs a new query builder for the given table with an alias.
LIGHTWEIGHT_API SqlQueryBuilder& FromTableAs(std::string table, std::string alias);

// Initiates INSERT query building
//
// @param boundInputs Optional vector to store bound inputs.
// If provided, the inputs will be appended to this vector and can be used
// to bind the values to the query via SqlStatement::ExecuteWithVariants(...)
/////////////////////////////////////////////////
/// Initiates INSERT query building
///
/// @param boundInputs Optional vector to store bound inputs.
/// If provided, the inputs will be appended to this vector and can be used
/// to bind the values to the query via SqlStatement::ExecuteWithVariants(...)
/////////////////////////////////////////////////
LIGHTWEIGHT_API SqlInsertQueryBuilder Insert(std::vector<SqlVariant>* boundInputs = nullptr) noexcept;

// Constructs a query to retrieve the last insert ID for the given table.
Expand Down

0 comments on commit 0ee3128

Please sign in to comment.