Skip to content
NorscodeNorscode

A database that comes included

ArticleBy the Norscode project

NorsDB gives you SQL-like queries and transactions right in the standard library — enough for real apps.

A database that comes included your app same language SQL NorsDB transactions

Most programs need somewhere to store things: users, posts, orders. In many languages it begins with choosing a database, installing a driver and connecting a library. In Norscode a database comes included.

NorsDB

The standard library has NorsDB, a lightweight database you talk to through familiar, SQL-like queries. You create tables, insert and fetch rows, and wrap several changes in a transaction that either goes all the way through or not at all. It is enough to run real applications — the website you are reading this on stores all its content in NorsDB.

Why it is good that it comes included

Having a database right in the standard library means you get started without setup, and that it is one less external part to keep updated. For an app that does not need a heavy database server alongside, it is often just right: little to operate, easy to move, and everything in one language.

Honest about what it is

NorsDB is made to be simple and to come included, not to compete with heavy databases built for enormous amounts of data and many concurrent writers. If you need that, you can still talk to an external database. But for the great majority of applications, "the one that comes included" is more than enough — and it saves you a whole layer of setup.

A database you do not have to choose, install and connect is a database you actually start using right away.

A little more than fetching one number

A real app does more than count rows. With std.db you create tables, insert and fetch data, and update it with ordinary SQL statements:

db.execute(h, "INSERT INTO notat (id, tekst) VALUES (1, 'hei')")
la tekst = db.query_text(h, "SELECT tekst FROM notat WHERE id=1")

For values that come from outside — from a user or an API — you should use the bound variants like execute_bundet and query_text_bundet. They keep the data separate from the statement itself, so a malicious input cannot change the query. That is the safe habit, and it is worth adopting from day one.

All or nothing

If several changes are to hang together — subtract from one account and add to another — you wrap them in a transaction with begin, commit and rollback, or let transaction do it for you. Either everything goes through, or nothing is done. You avoid ending up in a half-finished state if something fails midway.

When you need more

NorsDB is made to be simple and to come included, not to compete with heavy databases built for enormous amounts of data. If the need grows beyond that, you can still talk to an external database. But for the great majority of applications, "the one that comes included" is more than enough.

Related

Back to the overview