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

9

u/SearchFair3888 Apr 30 '26

Per AutoModerator's request I hereby confirm that this project did not use an LLM as part of the development process.

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.

3

u/Resident-Letter3485 May 01 '26

This is awesome!!!! I haven't seen anyone else attempt this before. I began tackling the same problem around 9 months ago, with a schema language that transpiles to a backend and client HLLs (currently focusing on TS).

Having a lot of fun comparing our designs! Check mine out (it's my first ever attempt at a compiler, has a lot of room for improvement)

https://github.com/bens-schreiber/cloesce

2

u/SearchFair3888 May 01 '26

Looks nice, good minimal syntax.
u/david-1-1 something related you described?

1

u/david-1-1 May 01 '26

The data language (SD) contains only text data type, no quotation marks, and uses pipe (|) to show the data in a tree. The feature mechanism is a PHP page containing definitions and functions dealing with the feature. The functions are called throughout the website code. CSS is handled like the style attribute, except CSP compliant. JS is handled by one file that, like for CSS, is generated automatically from js inline pieces and files, again CSP compliant.

1

u/SearchFair3888 May 01 '26

Got it. Could be good to design such way for DSL. But i don't know any general purpose try as main stream design

1

u/david-1-1 May 02 '26

I'm not following you.

2

u/SearchFair3888 May 01 '26

I want to add point here that, I'm working on query builder too for upcoming relase
https://github.com/nynrathod/doolang/tree/0.4.1/tests/dev_test/database/query_builder

this was imp part for making stuctured way for writing query not an ORM. As it gave easy for writing clean schmea to APIS design. Any thoughts?

btw im using it in my own live product

1

u/EducationalCan3295 May 01 '26

Product link?

1

u/SearchFair3888 May 01 '26

https://www.doocloud.dev/
Here it is, here full implementation I did, just define the schema and ready the rest API with all the config pipeline and deployment.

2

u/esotologist Apr 30 '26

This looks really cool! I'm trying to work on something similar that allows for builder like composition of such structs myself 

2

u/SearchFair3888 May 01 '26

Thanks, would you mind trying Doolang so I can get more feedback? And waht you are working on simialr, curios to know

1

u/SearchFair3888 May 01 '26

https://github.com/nynrathod/doolang/tree/main/tests/dev_test
Check out all the features supported by doolang. Bugs may still appear in active development.

1

u/david-1-1 May 01 '26

If you create your own tools, you can make your own data language that puts all configuration in one place. And that puts all functions in all languages (PHP, HTML, CSS, js) in one file for each feature. I did it, and it avoids bugs while making extending easy.

1

u/SearchFair3888 May 01 '26

Very interesting, would you mind to share waht u have created for this? and yeah make sense

1

u/david-1-1 May 01 '26 edited May 01 '26

I haven't created a public demo or written explanation. My time is limited. But you can ask questions. But also see my other answer, which has an overview.

1

u/bjarneh May 01 '26

Similar to PostGREST I guess?

https://docs.postgrest.org/en/v14/

2

u/SearchFair3888 May 01 '26

Yeah, but PostGREST on top of Postgres only, I know right now doolang support postgre oly but it open for new databases once implemented.
And for doolang schmea is first class definnation of system which goes byond with RBAC, query builder too https://github.com/nynrathod/doolang/blob/0.4.1/tests/dev_test/database/rbac/main.doo

See this RBAC. and Schmea itself comes with decorators and validation in full RFC format

2

u/bjarneh May 01 '26

Ok, just reminded me. Seems like a nice project!

2

u/SearchFair3888 May 01 '26

Honestly I got to know this later when I have reday most of design and feature of language. Later I realized postgres has this library. 

1

u/bjarneh May 01 '26

I don't think it is an official Postgres library, it just looks like it due to the similar webdesign. In the beginning the PostGREST library created a simple CRUD REST API for a Postgres database, then it turned into something more involved with automatic search queries, and authentication built in. I just tried it out once or twice many years ago.

1

u/tobega May 02 '26

The API and the database model have different reasons to change, though. But nice that you don't need 4

4

u/[deleted] May 01 '26

[removed] — view removed comment

2

u/Inconstant_Moo 🧿 Pipefish May 01 '26

Could you give some examples? Then the OP might think of a way to deal with it.

If you will tell me why the fen
appears impassible, I then
will tell you why I think that I
can get across it, if I try.

1

u/mediocrobot May 01 '26

How deeply do foreign ids resolve?

2

u/SearchFair3888 May 01 '26

As per the current implementation

userId: Int @foreign(User),

This resolves on the first level of the schema. And honestly, not tested in depth yet

2

u/[deleted] May 01 '26

[removed] — view removed comment

1

u/SearchFair3888 May 01 '26

Yeah honestly, this is a really good point, I agree with you.

I’m not trying to solve all of that right now though. Doolang is still early, so I kinda want these problems to show up naturally as it grows, and then figure out what actually makes sense instead of over-designing upfront.

Right now the main goal is just keeping things stupid simple for devs. I know this kind of tight alignment won’t always hold at scale, and that’s fine for now.

Later on I will probably add more flexible ways to handle these cases instead of forcing everything into one model.

Really appreciate you writing this, stuff like this actually helps shape where doolang goes 👍, but also welcoming if you have any design to solve here?

1

u/[deleted] May 01 '26

[removed] — view removed comment

1

u/SearchFair3888 May 01 '26

Agree, let see how it's shape. But great discussion not possible to apply anything but took full discussion as great feedback

3

u/[deleted] May 01 '26

[removed] — view removed comment

1

u/SearchFair3888 May 01 '26

Ok will take a look. But one honest question I have. As like others I made mistake to implement features no one asked me to implement. I solved my own problems for api development. I wanna make grow doolang but I feel very less traction of doolang which is expected. Doocloud my own cloud products working in production on top of doo. I don't know how any language development grow in community. Direct reach and engage or organic reach? Without anyone using I'm preventing doing anything to do on doolang even I knew this is not covered enough test cases. and which makes uncertainty of directions

1

u/Resident-Letter3485 May 01 '26 edited May 01 '26

I'm not totally following here. The return type of your example is completely static.

[typeof account_id, typeof [a.name], integer, real, real]  

Standard SQL is statically structured, so you can't ever run in to a scenario where user input changes what the structure of a query is. If you have a compiler who is aware of every structure within your SQL (via generating your migrations or parsing your migrations by hand), you can in theory write static analysis to determine the possible outputs, which is a narrow set.

The only thing that can break this would be dialects that allow execution of arbitrary strings, which you could simply detect and noop in a compiler:

RETURN QUERY EXECUTE format('SELECT %I FROM %I', col, tbl);  

As for your point on one role-based views, I do not think this needs to be implemented at the database level, but rather at the bridge between backend and client. If one role sees more than another role, the backend should be fetching the appropriate data in the manner best suited for the current users role. A solution for this is here, called "Data Sources", which I adapt into my language

Lastly, for your UI concerns: yes, you will find yourself needing to coerce data, sometimes returning a table or some joined structure of tables is not the most frontend friendly structure (though designing the tables from the first place to be frontend friendly does mitigate a lot of this in small applications in my experience). Having dedicated types for returning from the backend to the client was my solution for this, if you do not want to return some direct table (Model) then create a transport layer "Plain Old Object"

At the end of the day, there are still a lot of ways to nitpick my solution. Personally, I'm trying to optimize for simple applications and really answer the question "how fast can I make a full stack app?". It's not yet suited for enterprise use, and likely will not be for a long time. However, I have yet to run into a real wall that has stopped me from going further.