r/ProgrammingLanguages • • Apr 30 '26

Language announcement Doolang – your struct definition is your schema, your validation, and your HTTP contract

Most stacks make you define the same data model four times. Once for the database schema, once for the model class, once for validation, once for the API contract. They drift. They break. You maintain all four.

Doolang collapses them into one:

struct User {
    id: Int @primary @auto,
    email: Str @email,
    password: Str min(8),
}

struct Task {
    id: Int @primary @auto,
    title: Str @min(1) @max(200),
    userId: Int @foreign(User),
}

fn main() {
    let db = Database::Postgres()?;
    let app = Server::new(":3000");

    app.auth("/signup", "/login", User, db);
    app.crud("/tasks", Task, db);

    app.start();
}

doo run. That's a native binary with JWT auth, password hashing, input validation, SQL migration, and full CRUD. Annotations aren't library decorators; they're compiler constructs. The compiler generates the SQL schema and HTTP layer directly from the struct.

Built on Rust + LLVM. Automatic ownership and borrow system with auto clone/copy/move no explicit lifetimes. Structured concurrency, websocket, file, query builder, RBAC, rate limiting, CORS, logger, middleware all in stdlib. Typed error propagation with -> T ! ErrorType.

Alpha. Real bugs. I'm running DooCloud on it in production as the real test.

github.com/nynrathod/doolang
Benchmarks: github.com/nynrathod/doo-benchmark

25 Upvotes

42 comments sorted by

View all comments

13

u/Inconstant_Moo 🧿 Pipefish Apr 30 '26

This is nice.

A suggestion. Since you're making SQL integration part of the core language, you might take it a step further and supply us with some custom syntax. E.g. instead of writing:

let result: [Task] = db.rawWithParams(
    "SELECT * FROM tasks WHERE priority = $1 AND status != $2",
     [Priority::High, Status::Done]
)?;

... you could let us do something like:

let result: [Task] = db.rawWithParams(SQL{
    SELECT * FROM tasks
    WHERE priority = {High} AND status != {Done}
})?;

I've always hated those $1, $2 things because apart from anything else my interactions with a machine that can perform half-a-trillion floating-point instructions per second shouldn't involve me counting on my fingers.

3

u/Resident-Letter3485 May 01 '26

Doing something similar in my language, essentially:

sql foo(id: int) {  
"  
   SELECT * FROM ... WHERE id = {id}  
"  
}  

What is neat is when you make a language like this that handles your DB schema, you can validate all SQL against the schema during compile time. Eventually, I really want to explore something like this:

sql foo(id: int) -> Option<string> {  
"  
   SELECT name FROM ... WHERE id = {id}  
"  
}  

where we can actually determine at compile time if the query results are the correct type.

2

u/SearchFair3888 May 01 '26

Good examples. Thanks for sharing, though this is not align with doo syntax, but still I align complely with your suggestion.

Would you mind to share you language please?

1

u/Inconstant_Moo 🧿 Pipefish May 01 '26

Well this is definitely The Way. I've been working on an essay where I explain why this is basically the only sensible way to do SQL integration. Have you ever seen the JVA ORM? It's the dumbest thing I've ever seen.

1

u/SearchFair3888 May 01 '26

Yes, but I'm not expert yet in such design still learning. It seems design sql in language is huge part not just a typical language design. 

2

u/SearchFair3888 Apr 30 '26

That's great point. So valid. I really appreciate you look at here. Great suggestions with alignment of doolang vision having simple syntax. Considering this improvement, though, that variable is enum value so can't define variable {High} direct, but will find solution. Again thanks. 

And would you mind to give star to repo. Actively looking community feedback and users to use doolang. 

3

u/Inconstant_Moo 🧿 Pipefish Apr 30 '26 edited Apr 30 '26

But you just insert it how you would have done in the original example --- convert it into a number I presume. The {foo} bit doesn't mean "insert foo lexically", it means "evaluate foo, convert the resulting value to the appropriate type for storing it in the database, and then inject it with sanitation".

2

u/SearchFair3888 May 01 '26

It's clear now that it's a great insight. Thanks, very helpful for designing SQL query. Noted this for coming improvement.