We are excited to announce the initial alpha version of the Xata Go SDK.
Written by
Philip Krauss
Published on
December 6, 2023
Earlier this year we shared a community spotlight focused on a Go SDK developed by a dedicated contributor, xata-go.
Kerdo Kurs, the developer behind this project, was a huge inspiration for us committing to an official Go SDK. Today, we're thrilled to announce the official release of our Xata Go SDK, and open the doors to the growing Go community π
The v0.0.1
release features our most popular endpoints, enabling functionalities like searching a branch, using the ask endpoint for follow-up questions, and creating a database, among others.
You can see the evolving endpoint coverage in the ticket xata-go#1.
If you want to get started right away, head over to the Go SDK documentation and browse the code on GitHub.
In our documentation, we've included examples showing how to use the Go SDK, similar to the existing guides we have for TypeScript, Python, cURL, and SQL.
In the Go SDK, components are organized into specialized clients within distinct namespaces, like the RecordsClient
for record-related functions.
All endpoints that are listed in our API reference, are modeled within this client.
The available clients are:
BranchClient
DatabasesClient
FilesClient
RecordsClient
SearchAndFilterClient
TableClient
UsersClient
WorkspaceClient
The code and corresponding test suites can be found in the xata package.
If you're familiar with our SDKs, you'll notice familiar API naming patterns, adapted to align with Go's idiomatic style. To illustrate the usage of the Go SDK, we curated a couple of examples. Browse our docs to see the full bandwidth of examples.
The following example succinctly demonstrates, how to use the Ask endpoint.
For demo purposes we assume that the table IMDB
contains all movies listed from IMDB.com and we want to learn how many Ace Ventura movies exist.
More complex queries and follow up questions examples can be found here.
searchClient, _ := xata.NewSearchAndFilterClient()
result, _ := searchClient.Ask(context.TODO(), xata.AskRequest{
TableName: "IMDB",
Question: "How many Ace Ventura movies are there?",
})
In this example, we have not normalized data in multiple tables in one branch and want to search across this entire branch.
We are looking for the name Philip, but as there are multiple ways of writing Philip (such as Filip or Phillip or Philippe) we need to apply fuzziness to our search. Fuzziness: xata.Int(2)
sets the search fuzziness level to a degree of 2, allowing for slight variations in the spelling of search terms.
searchClient, _ := xata.NewSearchAndFilterClient()
results, _ := searchClient.SearchBranch(context.TODO(), xata.SearchBranchRequest{
Payload: xata.SearchBranchRequestPayload{
Query: "Philip",
Fuzziness: xata.Int(2),
},
})
The last example illustrates the use of the transaction endpoint. Transactions are a powerful way to do multiple operations in one go. For the sake of the example, we solely want to create multiple records of actors that participated in the movie the Matrix.
recordsClient, _ := xata.NewRecordsClient()
result, _ := recordsClient.Transaction(context.TODO(), xata.TransactionRequest{
Operations: []xata.TransactionOperation{
xata.NewInsertTransaction(xata.TransactionInsertOp{
Table: "Actors",
Record: map[string]any{
"name": xata.String("Keanu Charles Reeves"),
"movie": xata.String("the_matrix"),
},
Record: map[string]any{
"name": xata.String("Carrie-Anne Moss"),
"movie": xata.String("the_matrix"),
},
Record: map[string]any{
"name": xata.String("Laurence Fishburne"),
"movie": xata.String("the_matrix"),
},
}),
},
})
The SDK is an alpha release, and not all endpoints are covered, we continue to increase the API coverage of the SDK and provide bug fixes.
We can't do it without you! If you want to contribute code, add an example update the docs, or found a bug please open a PR or issue and we will assist you. All contributions are welcome β
To stay up to date with the latest at Xata, follow us on X | Twitter or pop in and say hi in Discord.
Is there a language you wished we supported natively but don't today? Feel free to open up a feature request or check-in with our amazing community.
Xata provides the best free plan in the industry. It is production ready by default and doesn't pause or cool-down. Take your time to build your business and upgrade when you're ready to scale.
Sign up to our newsletter
By subscribing, you agree with Xataβs Terms of Service and Privacy Policy.
Copyright Β© 2024 Xatabase Inc.
All rights reserved.