Instant GraphQL APIs on SQLite with Turso

While Hasura has become well known in the PostgreSQL world, not every project is PostgreSQL scale, and often developers find themselves reaching for tools like SQLite.

If you’ve ever found yourself wishing you could use Hasura-flavored GraphQL with your SQLite database, you’re in luck because today we are excited to announce the release of the Hasura Turso connector.

To try it out yourself,  get started with Hasura DDN here. The steps for working with the Turso connector can be found in this GitHub repository.

What can the Hasura Turso connector do?

The Hasura Turso connector can connect to a Turso SQLite database, introspect the underlying data, and expose a GraphQL API with queries and mutations for the database.

What capabilities does the Hasura Turso connector have?

The Hasura Turso connector comes with a handful of capabilities out of the box, with even more coming soon! Here’s an overview of queries you can currently run with the Hasura Turso connector.

Simple queries:

query Query {
  turso_album {
    albumId
    artistId
    title
  }
}

Queries with predicates:

query Query {
  simple_predicate: turso_album(where: {albumId: {_eq: 10}}) {
    albumId
    artistId
    title
  }
  and_predicate: turso_album(
    where: {_and: [{albumId: {_gt: 1}}, {albumId: {_lte: 2}}]}
  ) {
    albumId
    artistId
    title
  }
}

Queries with ordering and pagination:

query Query {
  order_by: turso_album(order_by: {albumId: Desc}) {
    albumId
    artistId
    title
  }
  paginate: turso_album(offset: 10, limit: 10) {
    albumId
    artistId
    title
  }
}

Queries with a combination of predicates, ordering, and pagination:

query Query {
  complex_query: turso_album(
    limit: 10
    offset: 10
    order_by: {albumId: Desc}
    where: {_or: [{albumId: {_lt: 10}}, {albumId: {_gt: 20}}]}
  ) {
    albumId
    artistId
    title
  }
}

The connector also supports querying with relationships:

query Query {
  relationship_query: turso_album {
    albumId
    title
    artist {
      artistId
      name
    }
    tracks {
      trackId
      name
    }
  }
}

Queries across relationships can utilize predicates, ordering, and pagination:

query Query {
  relationship_filter_query: turso_album {
    albumId
    title
    tracks(
      limit: 10
      order_by: {trackId: Desc}
      where: {name: {_like: "%Spellbound%"}}
    ) {
      trackId
      name
    }
  }
}

Queries can also filter across a relationship:

query Query {
  relationship_predicate_query: turso_album(
    where: {tracks: {name: {_like: "%Spellbound%"}}}
  ) {
    albumId
    title
    tracks {
      trackId
      name
    }
  }
}

The Turso connector also has support for performing mutations. Here are some of the mutations that are currently supported.

Insert one mutations:

mutation Mutation {
  turso_insertAlbumOne(object: {albumId: 1000, artistId: 10, title: "New Album"}) {
    albumId
    artistId
    title
  }
}

Update by primary key mutations:

mutation Mutation {
  turso_updateAlbumByPk(
    pkColumns: {albumId: 1000}
    set: {title: "The New Album"}
    inc: {artistId: 1}
  ) {
    albumId
    artistId
    title
  }
}

Delete by primary key mutations:

mutation Mutation {
  turso_deleteAlbumByPk(pkColumns: {albumId: 1000}) {
    albumId
    artistId
    title
  }
}

Conclusion

The Hasura Turso connector brings the power of GraphQL to SQLite databases, offering developers a versatile and efficient tool for their data management needs. Now you can run a variety of queries and mutations on your SQLite database with minimal setup.

The Turso connector even has support for additional operations such as delete many, insert many, and update many. Stay tuned because additional capabilities such as performing aggregations and grouping will be coming to the Turso connector.

Try it out yourself by getting started with Hasura DDN here. The steps for working with the Turso connector can be found in this GitHub repository.

Blog
03 Jul, 2024
Email
Subscribe to stay up-to-date on all things Hasura. One newsletter, once a month.
Loading...
v3-pattern
Accelerate development and data access with radically reduced complexity.