DEV Community

Cover image for Announcing the release of the Xata Go SDK
Joan for Xata

Posted on • Originally published at xata.io

Announcing the release of the Xata Go SDK

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.

Anatomy of the SDK

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?",
})
Enter fullscreen mode Exit fullscreen mode

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),
  },
})
Enter fullscreen mode Exit fullscreen mode

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"),
      },
    }),
  },
})
Enter fullscreen mode Exit fullscreen mode

Whatโ€™s next?

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 that 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.

Top comments (0)