- Secure and Modern Syntax: Provide a SQL-compatible language with a secure and modern syntax, including type checking to eliminate runtime errors.
- Enhance Readability: Improve the readability and maintainability of SQL queries.
- Support Complex Queries: Enable the creation of complex queries with ease, including joins, subqueries, and more, with expressiveness comparable to SQL, as much as possible.
- Multi-language Support: Ensure that nsql can be ported to various programming languages and databases, allowing developers to utilize nsql in different environments, to make the knowledge of nsql applicable everywhere.
- Design for IDE Autocompletion: Prioritize design that facilitates autocompletion in IDEs.
We are still in the early stages, but we welcome contributions. We have a goal to port nsql to various languages and databases, so we especially welcome the creation of drivers for different languages.
Feel free to use Issues or PRs. There are no specific rules for now. Please refer to the following Roadmap when contributing.
- Rust (latest stable)
- Node.js (for VSCode extension development)
- VSCode (for testing the extension)
next-sql/
├── nextsql-core/ # Core parser and AST library
├── nextsql-cli/ # Command-line interface
├── nextsql-lsp/ # Language Server Protocol implementation
├── nextsql-vscode/ # VSCode extension
├── examples/ # Example NextSQL files
└── migrations/ # Database migration files
# Build all components
cargo build
# Run tests
cargo test
# Build specific component
cargo build -p nextsql-cli
cargo build -p nextsql-lsp-
Build the Language Server:
cargo build -p nextsql-lsp
-
Install extension dependencies:
cd nextsql-vscode npm install -
Compile the extension:
npm run compile
-
Test the extension:
- Open VSCode
- Open the
nextsql-vscodefolder - Press
F5to launch Extension Development Host - In the new window, open or create a
.nsqlfile - Test syntax highlighting, error detection, and autocompletion
- Syntax Highlighting: Color coding for NextSQL keywords, types, and operators
- Error Detection: Real-time syntax error highlighting
- Autocompletion: Context-aware method suggestions when typing
. - Language Server: Full LSP integration for enhanced development experience
# Initialize a new NextSQL project
cargo run -- init [--dir <directory>]
# Run a NextSQL file
cargo run -- <file.nsql>
# Migration commands
cargo run -- migration init
cargo run -- migration generate <name> --description "<description>"
cargo run -- migration list
cargo run -- migration up
cargo run -- migration down <timestamp>
# Database operations
cargo run -- migration db-up
cargo run -- migration db-down <timestamp>
cargo run -- migration db-statusNextSQL projects use a next-sql.toml configuration file to define project settings:
# Files to include in parsing (supports glob patterns)
includes = ["src/**"]
# Target language for code generation
target_language = "rust"
# Output directory for generated code
target_directory = "../generated"The nsql init command creates a new NextSQL project with default configuration:
# Initialize in current directory
cargo run -- init
# Initialize in specific directory
cargo run -- init --dir my-projectYou can see a complete example project in the examples/sample-project directory.
query findUserById($id: uuid) {
from(users)
.where(users.id == $id)
.select(users.*)
}
query findUserWithPosts($id: uuid) {
alias u = users
alias p = posts
from(users.innerJoin(posts, u.id == p.user_id))
.where(u.id == $id)
.select(u.name, p.title, p.content)
}
mutation insertUser($name: string, $email: string) {
insert(users)
.value({
name: $name,
email: $email,
})
.returning(users.*)
}
NextSQL uses explicit alias statements for better IDE autocompletion support:
query example() {
alias u = users
alias p = posts
from(users.innerJoin(posts, u.id == p.user_id))
.select(u.name, p.title)
}
Join operations are part of the from clause:
from(table1.innerJoin(table2, condition))from(table1.leftJoin(table2, condition))from(table1.rightJoin(table2, condition))from(table1.fullOuterJoin(table2, condition))from(table1.crossJoin(table2, condition))
Multiple joins can be chained:
from(users.innerJoin(posts, u.id == p.user_id).leftJoin(comments, p.id == c.post_id))
NextSQL includes a comprehensive type system:
- Built-in types:
i16,i32,i64,f32,f64,string,bool,uuid,timestamp,date - Optional types:
T?(e.g.,string?) - Array types:
[T](e.g.,[string]) - Utility types:
Insertable<T>for insert operations
