You can access your Vitess cluster using a variety of clients and programming languages. Vitess client libraries help your client application to more easily talk to your storage system to query data.
Vitess' service is exposed through a proto3 service definition. Vitess supports gRPC, and you can use the proto compiler to generate stubs that can call the API in any language that the gRPC framework supports.
This document explains the client library strategy for Vitess.
Vitess client libraries follow these core principles:
vtgate service. The connection object should be
thread-safe, if applicable, and should support multiplexing for
streaming queries, transactions, and other operations that rely
on multiple queries.vtgateclienttest, enabling you to
fully unit-test all API calls. vtgateclienttest is
a small server that simulates a real vtgate server
and returns specific responses to allow for full client feature
coverage.The Go client interface is in the "vtgateconn" package.
There are multiple implementations available. We recommend to use the "grpc" implementation. Load it by importing its package:
import "github.com/youtube/vitess/go/vt/vtgate/grpcvtgateconn"
When you connect to vtgate, use the
DialProtocol method
and specify "grpc" as protocol.
Alternatively, you can set the
command line flag "vtgate_protocol"
to "grpc".
The Go client interface has multiple Execute*() methods for different use-cases
and sharding configurations. When you start off with an unsharded database, we
recommend to use the
ExecuteShards method
and pass "0" as only shard.
For an example how to use the Go client, see the end-to-end test local_cluster_test.go. From this test file, you can also reuse the "LaunchVitess" call to instantiate a minimal Vitess setup (including a MySQL server). This way you can test your application against an actual instance.