r/Database • • 1h ago

dbml.db playground

Thumbnail dbml.db.pit.world
0 Upvotes

r/Database • • 14h ago

Advent of SQL and NoSQL – 24 challenges leading up to Christmas

Post image
7 Upvotes

Happy Holidays, r/Database!

I've noticed that most Advent of SQL events are exclusively SQL-based, and NoSQL databases are usually left out.

This project was originally supposed to be SQL-only, but after roughly 2 years of working on VisuaLeaf, I managed to build an embeddable, MongoDB-compatible database that runs entirely on the frontend, allowing you to execute MongoDB queries and aggregation pipelines directly in your browser without a database server.

Somebody tampered with Santa's Nice List, and you're the North Pole's first-ever data elf.

That's the story behind Advent of SQL & NoSQL: 24 puzzles, one a day from December 1 to 24. Every day, you get a bit more of the story and a question to answer with a query: which toys to build first, which children flipped from nice to naughty overnight, whose badge was used on the night shift, who walked through which door and when. By Christmas Eve, you'll have worked out who did it and fixed the list.

You can solve the whole thing in one of four databases, following the same story and working with the same underlying data:

  • SQLite
  • DuckDB
  • PostgreSQL
  • MongoDB (mongosh, aggregation pipelines)

More details:

  • Everything runs entirely in your browser. There's nothing to install, no backend database server, and nothing to connect to.
  • Your answer gets checked instantly, against the data you see and against hidden datasets with different values. Reading the answer off the screen and hard-coding it won't pass.
  • It gets harder as it goes. Early days cover basic filtering, grouping and joins. Later ones require window functions, recursive CTEs, relational division, advanced MongoDB aggregation pipelines and running totals.
  • Database-specific data modeling. The MongoDB version isn't just SQL tables converted into collections. It uses embedded documents, arrays and aggregation patterns that you'd actually encounter when working with MongoDB.
  • Hints and traps for each day, if you get stuck, plus a short "did you know" tip about your chosen database.

A new puzzle unlocks every day until Christmas Eve!

Pick your database here: https://visualeaf.com/advent-of-sql-and-nosql/

Completely free. No account, no installation, no database server needed.

I hope you all enjoy it, and happy holidays!


r/Database • • 12h ago

Advice on dealing with similar column patterns in schema design

5 Upvotes

When there is a similar sets of columns to include in a schema design, I see two issues that come up often, and disagreement on how to handle them. The first I'll call the "sub-type issue" and the second the "nesting issue". I wonder how different shops deal with each.

A recent example I encountered for the sub-type issue is an event tracking system where participants and witnesses are logged. Let's say there's a scuffle at the local mall and the mall cops have to document it. (Not actual domain, but close.) What you might call "key people" have many more columns associated with them, but "incidental people" just need a name and optional phone number.

My feeling is to make one table, "Participants" with with a Participant Type column (FK). But the primary DB architect decided on two tables: "Key Participants" and "Incidental Participants". In practice a person won't need to be switched between categories often; the few times it happens app users just delete the old record and create a new one. The architect's reasoning was this allows the schema to enforce required columns (not null), whereas a single table has to enforce such algorithmically, based on the Participant Type column. To me that seems kind of a weak reason because it complicates the schema. Your view? (If participants did hop categories often, then a single table would clearly be better.)

The second type, the "nesting issue" is that there is a primary location and potential secondary locations. An Event record is to have one and only one primary location, but can have many secondary. There's about 10 columns associated with a location. My feeling was to put both types in a Location table with a location-type column, but the architect instead decided to include those 10 columns in the Event table, to record the primary location. The others go into the Secondary Locations table. The architect claims it makes application programming easier because writing an event would only have to write or change one record instead of two, at least for the general Event form. Agree or disagree? What factors drive you toward one approach versus another? Thanks!