Mengumumkan Ketersediaan Umum C++ SDK untuk Couchbase

王林
Lepaskan: 2024-07-19 16:37:42
asal
463 orang telah melayarinya

Announcing General Availability of the C++ SDK for Couchbase

We are thrilled to announce the General Availability (GA) of the C++ SDKfor Couchbase! This release adds support for native C++ language to our existing comprehensive set of SDK libraries in 11 programming languages and marks a significant milestone in our commitment to providing robust, high-performance tools for developers to build modern, scalable applications. In fact, this C++ SDK is the core library behind our existing Python, NodeJS, Ruby, and PHP SDKs and strives to provide a consistent, performant and efficient experience across all these programming languages.

Why C++ SDK?

C++ remains a vital language for many developers due to its performance, efficiency, and control over system resources. By introducing the C++ SDK, Couchbase empowers developers to leverage these advantages while taking full benefit of Couchbase’s advanced NoSQL capabilities. Here are some key reasons why this release is a game-changer:

Performance

C++ is renowned for its speed and low-level memory management, making it ideal for applications where performance is critical. The C++ SDK for Couchbase ensures that you can build high-performance applications without sacrificing speed or efficiency.

Seamless Integration

The C++ SDK provides seamless integration with Couchbase Server, enabling developers to easily perform operations such as KV operations, SQL++ queries, and transactions. This tight integration ensures that your applications can scale effectively while maintaining high performance.

Modern API Design

The C++ SDK features a modern, idiomatic API that aligns with the latest C++ standards. This makes it not only powerful but also intuitive for C++ developers, reducing the learning curve and allowing you to start building applications quickly.

Key Features

Here are some of the standout features of the C++ SDK for Couchbase:

Easy Connection Management

The C++ SDK simplifies connection management, allowing you to establish and manage connections to your Couchbase cluster with minimal effort. This includes handling connection pooling, load balancing, and failover, ensuring your application remains resilient and performant. This means that the SDK can automatically read the topology of your cluster and provide seamless connections during topology changes such as cluster resizes or cluster upgrades. Below is an example of C++ code to connect to your couchbase database.

// Attempt to connect to the Couchbase cluster auto [connect_err, cluster] = couchbase::cluster::connect(config.connection_string, options).get(); if (connect_err) { // Output the error message if connection fails std::cout << "Unable to connect to the cluster. Error code: " << connect_err.message() << "\n"; } else { auto collection = cluster.bucket(config.bucket_name) .scope(config.scope_name) .collection(config.collection_name); // d something interesting cluster.close().get(); }
Salin selepas log masuk

Key-Value (KV) Operation Support

The C++ SDK natively supports performing key value operations. Key-value operations are unique to couchbase and provide very fast CRUD operations for documents stored in couchbase. Below is an example of C++ code to run a simple KV get & upsert of a document.

auto collection = cluster.bucket(config.bucket_name) .scope(config.scope_name) .collection(config.collection_name); // KV- get auto record = collection.get(document_id); std::cout << record.content_as() << "\n"; // create a new document const std::string document_id{ "minimal_example" }; const tao::json::value basic_doc{ { "a", 1.0 }, { "b", 2.0 }, }; // KV auto [err, resp] = collection.upsert(document_id, basic_doc, {}).get(); if (err.ec()) { std::cout << "ec: " << err.message() << ", "; } else { std::cout << "id: " << document_id << ", CAS: " << resp.cas().value() << "\n"; } cluster.close().get();
Salin selepas log masuk

Rich Query, Search and Vector Search Support

The C++ SDK supports SQL++ queries, full-text search (FTS), and vector search, providing you with powerful tools to perform complex data operations. Whether you need to run sophisticated queries or perform full-text searches, the SDK has you covered.

Query Search

Below is a code snippet to execute a simple SQL++ query to fetch records from airlines collection:

auto scope = cluster.bucket(config.bucket_name).scope(config.scope_name); auto [err, resp] = scope.query("SELECT * FROM airline LIMIT 10").get(); std::cout << "--- Iterating as JSON objects:\n"; for (auto row : resp.rows_as_json()) { std::cout << "Airline(id: " << row["airline"]["id"] << ", name: \"" << row["airline"]["name"] << "\")\n"; }
Salin selepas log masuk

Full Text Search (FTS)

Below is a code snippet to execute a FTS query to do a full text search for “nice restaurants” the index created on the landmark collection:

auto scope = cluster.bucket(config.bucket_name).scope(config.scope_name); auto [err, resp] = scope .search("travel-inventory-landmarks", couchbase::search_request(couchbase::query_string_query("nice restaurants")), couchbase::search_options{}.fields({ "content" })) .get(); for (const auto& row : resp.rows()) { auto fields = row.fields_as(); std::cout << "score: " << row.score() << ", id: \"" << row.id() << "\", content: \"" << fields["content"].get_string() << "\"\n"; }
Salin selepas log masuk

Vector Search

Below is a code snippet to execute a vector search query:

auto scope = cluster.bucket(config.bucket_name).scope(config.scope_name); // weights could be retrieved from your llm model or openAI std::vector weights{ 0.1, 0.2, 0.3, 0.4 }; auto [err, resp] = scope .search("travel-inventory-landmarks", couchbase::search_request(couchbase::vector_search( couchbase::vector_query(field_name, weights)))) .get(); for (const auto& row : resp.rows()) { auto fields = row.fields_as(); std::cout << "score: " << row.score() << ", id: \"" << row.id() << "\", content: \"" << fields["content"].get_string() << "\"\n"; }
Salin selepas log masuk

Asynchronous Programming

The SDK supports asynchronous programming models, enabling you to build responsive, non-blocking applications. This is particularly useful for high-throughput applications where maintaining responsiveness is essential. Here’s an example of running a transaction in a asynchronous context:

std::shared_ptr ctx) -> couchbase::error { ctx->get( collection, some_id, // do something in this transaction }
Salin selepas log masuk

Transactions

This new C++ SDK includes support for transactions and replaces our existing C++ transaction support by adding more performance improvements and features. Below is a sample code snippet for create a transaction context:

std::shared_ptr ctx) -> couchbase::error { ctx.insert(collection, "doc-a", nlohmann::json({})); couchbase::transactions::transaction_get_result doc_a = ctx->get( collection, “doc-a”) }
Salin selepas log masuk

Robust Error Handling

Error handling is crucial in any application, and the C++ SDK, just like our other SDKs, provides comprehensive error handling capabilities including retry for connection drops, connection pooling and informative error messages. This ensures that you can gracefully handle and recover from errors, enhancing the stability and reliability of your applications.

はじめる

C++ SDK for Couchbase を使い始めるのに役立つように、ドキュメント Web サイトに詳細なスタート ガイドを用意しました。開始方法の簡単な概要は次のとおりです:

    • SDK をインストールします: ドキュメントのインストール手順に従って、開発環境に SDK をセットアップします。
    • クラスターに接続する: Couchbase クラスターに接続します。
    • CRUD 操作を実行し、クエリを実行し、Couchbase の強力な機能を活用します。

コミュニティとサポート

私たちはコミュニティとオープンソース開発の力を信じています。 Couchbase 用の C++ SDK はオープンソースです。貢献し、フィードバックを提供し、会話に参加することをお勧めします。サポートについては、エンタープライズ ライセンスを取得した顧客の場合は、サポート経由で問い合わせることができます。そうでない場合は、包括的なドキュメントにアクセスするか、Couchbase フォーラムまたは Couchbase Discord に参加するか、サポート ポータル経由で問い合わせることができます。

参考文献

詳細については、ドキュメント Web サイトをご覧ください。 API、特にトランザクションと非同期操作について詳しく説明し、さらに深く掘り下げるための他の参考資料とサンプル バインディングのリンクを提供します。

    • Couchbase C++ SDK コード例
    • Couchbase C++ SDK ドキュメント
    • Couchbase C++ SDKをダウンロードしてインストールします
サポートされているオペレーティング システムは、ドキュメント Web サイトにリストされています。

コーディングを楽しんでください!

カウチベースチーム

Couchbase 用 C++ SDK の一般提供を発表するという投稿は、The Couchbase Blog に最初に掲載されました。

Atas ialah kandungan terperinci Mengumumkan Ketersediaan Umum C++ SDK untuk Couchbase. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

sumber:dev.to
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!