Skip to Content
CockroachDB: The Definitive Guide, 2nd Edition
book

CockroachDB: The Definitive Guide, 2nd Edition

by Guy Harrison, Jesse Seldess, Ben Darnell, Rob Reid
March 2025
Intermediate to advanced
542 pages
8h 50m
Japanese
O'Reilly Media, Inc.
Content preview from CockroachDB: The Definitive Guide, 2nd Edition

第6章 アプリケーションの設計 アプリケーションの設計と実装

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

すべてのデータベースと同様に、CockroachDBはアプリケーションコードからのリクエストに応答する。 アプリケーションがどのようにデータを要求し、使用するかは、アプリケーションのパフォーマンスとスケーラビリティに大きく関係する。 この章では、CockroachDBリクエストとトランザクション・モデルをコーディングするためのベスト・プラクティスを含め、アプリケーションがCockroachDBとどのように連携すべきかをレビューする。

CockroachDBはPostgreSQLワイヤ・プロトコル互換であるため、PostgreSQLをサポートするプログラミング言語であればCockroachDBで使用できる。 また、一般化として、PostgreSQLのプログラミング・イディオムとベスト・プラクティスがCockroachDBに適用される。 ただし、CockroachDBは分散型であるため、CockroachDBとPostgreSQLではプログラミング・スタイルに若干の違いがある。

CockroachDBは、一般的に使用されているプログラミング言語であれば、ほぼすべての言語を使用して作業できるが、この章では、4つの言語に限定して説明する: Go、Java、Python、JavaScriptである。

前回、各言語のドライバをインストールする方法を示した。 ドライバのインストール方法については第3章に戻るか、他の言語のドライバや代替ドライバのインストール方法を含むより詳細なガイドラインについてはCockroachDBのドキュメントを参照してほしい。

CockroachDBプログラミング

CockroachDBは、SQLリレーショナルデータベースと幅広く互換性があり、特にPostgreSQLと互換性がある。 しかし、分散トランザクションの性質とトランザクション一貫性モデルの結果として、CockroachDB特有のプログラミング・イディオムがいくつかある。

以下のセクションでは、CockroachDBサーバに対してアプリケーションをコード化する際の一般化原則をレビューし、CockroachDBに特有の問題をいくつか見ていく。

CRUD演算子の実行

基本的な "Hello world "の例()を第3章で各言語ごとに紹介した。それらの例を拡張して、Create、Read、Update、Deleteといった、自明でないCRUD演算子を実行してみよう。

プログラミング・ドライバは、語彙の点で異なるが、一般的に同様の文法を採用している。 データベースプログラムにおける基本的な演算子は以下の通りである:

  • ドライバはデータベースサーバへの接続を表す接続オブジェクト を確立する。この章では個別の接続を作成するが、アプリケーションでは多くの場合、接続プールを使用して再利用可能な複数の接続を管理する。

  • 接続オブジェクトはSQL文の実行に。

  • いくつかのステートメントは、SELECT ステートメント、RETURNING 節を含む DML ステートメント、および結果を返すその他のステートメントによって返される表形式出力を反復するために使用できる結果セットを返す。

ここでは、Javaのこの基本パターンを見てみよう:

package chapter06c;

import java.sql.Connection ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

CockroachDB: The Definitive Guide, 2nd Edition

CockroachDB: The Definitive Guide, 2nd Edition

Guy Harrison, Jesse Seldess, Ben Darnell, Rob Reid
CockroachDB: The Definitive Guide

CockroachDB: The Definitive Guide

Guy Harrison, Jesse Seldess, Ben Darnell

Publisher Resources

ISBN: 9798341634695