Skip to content

Commit

Permalink
sketch driver stub recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Sep 24, 2024
1 parent 14167cd commit f9a5b7e
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
46 changes: 46 additions & 0 deletions docs/source/cpp/driver_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

cmake_minimum_required(VERSION 3.18)

project(adbc_cookbook_recipes_driver
VERSION "1.0.0"
LANGUAGES CXX)

include(CTest)
include(FetchContent)

set(CMAKE_CXX_STANDARD 17)

# TODO: This currently depends on about-to-be-released nanoarrow, which allows
# access to both nanoarrow and the IPC reader using a single fetchcontent.
set(NANOARROW_IPC ON)
set(NANOARROW_NAMESPACE "DriverExamplePrivate")
fetchcontent_declare(nanoarrow
GIT_REPOSITORY https://github.com/apache/arrow-nanoarrow.git
GIT_TAG main
GIT_SHALLOW TRUE)
fetchcontent_makeavailable(nanoarrow)

add_library(adbc_driver_framework ../../../../c/driver/framework/utility.cc
../../../../c/driver/framework/objects.cc)
target_include_directories(adbc_driver_framework PRIVATE ../../../../c ../../../../c/include)
target_link_libraries(adbc_driver_framework PRIVATE nanoarrow::nanoarrow)

add_library(driver_example SHARED driver_example.cc)
target_include_directories(driver_example PRIVATE ../../../../c ../../../../c/include)
target_link_libraries(driver_example PRIVATE adbc_driver_framework nanoarrow::nanoarrow)
72 changes: 72 additions & 0 deletions docs/source/cpp/driver_example/driver_example.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#include "driver/framework/connection.h"
#include "driver/framework/database.h"
#include "driver/framework/statement.h"

#include "nanoarrow/nanoarrow.hpp"
#include "nanoarrow/nanoarrow_ipc.hpp"

#include "arrow-adbc/adbc.h"

using adbc::driver::Option;
using adbc::driver::Result;
using adbc::driver::Status;

class DriverExampleDatabase : public adbc::driver::Database<DriverExampleDatabase> {
public:
[[maybe_unused]] constexpr static std::string_view kErrorPrefix = "[example]";

Status SetOptionImpl(std::string_view key, Option value) override {
if (key == "uri") {
UNWRAP_RESULT(uri_, value.AsString());
return adbc::driver::status::Ok();
}

return Base::SetOptionImpl(key, value);
}

Result<Option> GetOption(std::string_view key) override {
if (key == "uri") {
return Option(uri_);
}

return Base::GetOption(key);
}

private:
std::string uri_;
};

class DriverExampleConnection : public adbc::driver::Connection<DriverExampleConnection> {
public:
[[maybe_unused]] constexpr static std::string_view kErrorPrefix = "[example]";
};

class DriverExampleStatement : public adbc::driver::Statement<DriverExampleStatement> {
public:
[[maybe_unused]] constexpr static std::string_view kErrorPrefix = "[example]";
};

static AdbcStatusCode ExampleDriverInitFunc(int version, void* raw_driver,
AdbcError* error) {
using ExampleDriver =
adbc::driver::Driver<DriverExampleDatabase, DriverExampleConnection,
DriverExampleStatement>;
return ExampleDriver::Init(version, raw_driver, error);
}

0 comments on commit f9a5b7e

Please sign in to comment.