Open Source DSL for SQL Generation

Type-safe SQL,
beautifully expressed.

Write SQL queries as composable, typed functions. Generate production-ready database modules for your language.

queries.nsql
// Define a relation — auto-generates JOINs
relation author for posts returning users {
    users.id == posts.author_id
}

query findPostsByAuthor($authorName: string) {
    from(posts)
    .where(posts.author.name == $authorName)
    .select(posts.title, posts.author.email)
}
// why NextSQL

Built for real-world databases

NextSQL bridges the gap between raw SQL and type-safe application code, giving you expressiveness without sacrificing safety.

Compile-time Type Safety

Catch SQL errors before runtime. Schema-aware validation ensures your queries match your database at build time.

Code Generation

Generate idiomatic, production-ready modules for your target language. Currently supports Rust with more languages planned.

IDE-first Design

VSCode extension with LSP support provides real-time error detection, context-aware autocompletion, and syntax highlighting.

Relations & Auto-JOINs

Declare relationships once, then navigate them with dot notation. NextSQL resolves JOINs automatically from your definitions.

Up and running in minutes

Install the CLI, initialize your project, write a query, and generate code.

1

Install NextSQL CLI

$ curl -fsSL https://github.com/shirakawayohane/next-sql/releases/latest/download/nextsql-cli-installer.sh | bash
> irm https://github.com/shirakawayohane/next-sql/releases/latest/download/nextsql-cli-installer.ps1 | iex
2

Initialize a project

Create a next-sql.toml config and directory structure.

$ nsql init my-project
3

Write your first query

Create a .nsql file with type-safe query definitions.

query findUserById($id: uuid) {
  from(users)
  .where(users.id == $id)
  .select(users.*)
}
4

Generate code

Run the generator and get type-safe Rust modules ready for use.

$ nsql gen

First-class IDE experience

Install the VSCode extension for syntax highlighting, real-time error detection, and context-aware autocompletion.

NextSQL Language Support

  • Syntax highlighting for .nsql files
  • Real-time error detection via language server
  • Autocompletion triggered by .
  • Schema-aware diagnostics
Install from Marketplace