Kapitel 4 · Die Dienste

saims.db — die Datenbank

Kein SQL, sondern ein Bauplan: Die Plattform prüft jeden Bezeichner und bindet jeden Wert. Setzt db:own-schema voraus.

Du schreibst kein SQL, sondern einen Bauplan. Die Plattform prüft jeden Bezeichner und bindet jeden Wert — SQL-Injektion gibt es nicht. Der Zeilentyp beschreibt die Tabelle, ohne tenant_id:

interface Antrag {
  readonly id: string;
  readonly von: string;
  readonly status: 'offen' | 'genehmigt' | 'abgelehnt';
}

Steht tenant_id im Zeilentyp, wird der Tabellenname unzuweisbar und der Aufruf scheitert schon beim Übersetzen — den Mandanten setzt die Plattform.

Lesen und schreiben

// Lesen
await saims.db.from<Antrag>('antraege').orderBy('von', 'desc').selectAll();
await saims.db.from<Antrag>('antraege').where({ status: 'offen' }).count();
await saims.db.from<Antrag>('antraege').where({ id }).first();

// Schreiben — tenant_id setzt die Plattform
const angelegt = await saims.db.insert<Antrag>('antraege', { von, bis });
angelegt.id;                                      // die vergebene Kennung
await saims.db.update<Antrag>('antraege', { status: 'genehmigt' }, { id });
await saims.db.remove<Antrag>('antraege', { id });

Vergleiche

Ein Wert heißt Gleichheit, null heißt IS NULL. Für alles andere gibt es Vergleichsfunktionen aus @saims/sdk (gt, gte, lt, lte, ne, oneOf, noneOf, contains, startsWith, isSet, isNull):

.where({ von: lte(bis), bis: gte(von) })          // überlappende Zeiträume
.where({ status: oneOf(['offen', 'genehmigt']) }) // mehrere Zustände
.where({ grund: contains('urlaub') })             // ohne Rücksicht auf Groß/Klein
🧩

oneOf([]) findet nichts — nicht alles. Das macht einen Filter „alle gewählten Zustände" richtig. contains maskiert % und _: Wer nach „50 %" sucht, sucht nach „50 %".

Oder-Gruppen, Seiten, Rechnen

// Oder-Gruppe (eine Ebene tief, nur beim Lesen)
.whereAny([{ name: contains(s) }, { email: contains(s) }])
// → … AND (name ILIKE … OR email ILIKE …)

// Seitenweise — EINE Abfrage, Gesamtzahl inklusive
const { zeilen, gesamt } = await saims.db.from<Eintrag>('eintraege')
  .orderBy('datum', 'desc').seite({ nummer: 3, groesse: 20 });

// In der Datenbank rechnen
.groupBy('projekt_id').aggregate({ minuten: 'sum', anzahl: 'count' });

Die Liste in whereAny ist das Oder, das einzelne Objekt bleibt ein Und. seite zählt in einer Anweisung (count(*) OVER ()) — zwei Abfragen könnten auseinandergehen. aggregate kennt nur sum, avg, min, max, count; gerechnet wird in der Datenbank, nicht durch Laden jeder Zeile.

Mehrere Schreibvorgänge als einer

const schritte = await saims.db.inEinemZug((zug) => {
  zug.insert('koepfe', { nummer: 4711 });
  zug.insertMany('positionen', zeilen);
  zug.update('vorlagen', { zuletzt: heute }, { id: vorlage });
});
const kopf = schritte[0]!.zeile as Kopf | null;

Alles darin geht ganz durch oder gar nicht (höchstens 100 Schritte). Gelesen wird darin nicht — was gelesen werden muss, wird vorher gelesen; sonst baust du eine Ablaufsteuerung über eine Grenze, die später ein Netz ist.

🚫

Was es nicht gibt: kein JOIN, keine Unterabfragen, keine freien Ausdrücke in aggregate. Wer mehr braucht, hat einen Befund über das SDK — melden statt umgehen.

Chapter 4 · The Services

saims.db — the database

Not SQL, but a blueprint: the platform checks every identifier and binds every value. Requires db:own-schema.

You don't write SQL, you write a blueprint. The platform checks every identifier and binds every value — SQL injection does not exist. The row type describes the table, without tenant_id:

interface Antrag {
  readonly id: string;
  readonly von: string;
  readonly status: 'offen' | 'genehmigt' | 'abgelehnt';
}

If tenant_id is in the row type, the table name becomes unassignable and the call fails at compile time already — the tenant is set by the platform.

Reading and writing

// Lesen
await saims.db.from<Antrag>('antraege').orderBy('von', 'desc').selectAll();
await saims.db.from<Antrag>('antraege').where({ status: 'offen' }).count();
await saims.db.from<Antrag>('antraege').where({ id }).first();

// Schreiben — tenant_id setzt die Plattform
const angelegt = await saims.db.insert<Antrag>('antraege', { von, bis });
angelegt.id;                                      // die vergebene Kennung
await saims.db.update<Antrag>('antraege', { status: 'genehmigt' }, { id });
await saims.db.remove<Antrag>('antraege', { id });

Comparisons

A value means equality, null means IS NULL. For everything else there are comparison functions from @saims/sdk (gt, gte, lt, lte, ne, oneOf, noneOf, contains, startsWith, isSet, isNull):

.where({ von: lte(bis), bis: gte(von) })          // überlappende Zeiträume
.where({ status: oneOf(['offen', 'genehmigt']) }) // mehrere Zustände
.where({ grund: contains('urlaub') })             // ohne Rücksicht auf Groß/Klein
🧩

oneOf([]) finds nothing — not everything. That makes a filter "all selected states" correct. contains escapes % and _: whoever searches for "50 %" searches for "50 %".

Or-groups, pages, calculating

// Oder-Gruppe (eine Ebene tief, nur beim Lesen)
.whereAny([{ name: contains(s) }, { email: contains(s) }])
// → … AND (name ILIKE … OR email ILIKE …)

// Seitenweise — EINE Abfrage, Gesamtzahl inklusive
const { zeilen, gesamt } = await saims.db.from<Eintrag>('eintraege')
  .orderBy('datum', 'desc').seite({ nummer: 3, groesse: 20 });

// In der Datenbank rechnen
.groupBy('projekt_id').aggregate({ minuten: 'sum', anzahl: 'count' });

The list in whereAny is the or, the single object remains an and. seite counts in one statement (count(*) OVER ()) — two queries could diverge. aggregate knows only sum, avg, min, max, count; the calculation happens in the database, not by loading every row.

Several writes as one

const schritte = await saims.db.inEinemZug((zug) => {
  zug.insert('koepfe', { nummer: 4711 });
  zug.insertMany('positionen', zeilen);
  zug.update('vorlagen', { zuletzt: heute }, { id: vorlage });
});
const kopf = schritte[0]!.zeile as Kopf | null;

Everything in it goes through entirely or not at all (at most 100 steps). No reading happens inside — whatever must be read is read beforehand; otherwise you're building control flow across a boundary that later is a network.

🚫

What doesn't exist: no JOIN, no subqueries, no free-form expressions in aggregate. Whoever needs more has a finding about the SDK — report it instead of going around it.

Chapitre 4 · Les services

saims.db — la base de données

Pas de SQL, mais un plan de construction : la plateforme vérifie chaque identifiant et lie chaque valeur. Présuppose db:own-schema.

Tu n'écris pas de SQL, mais un plan de construction. La plateforme vérifie chaque identifiant et lie chaque valeur — l'injection SQL n'existe pas. Le type de ligne décrit la table, sans tenant_id :

interface Antrag {
  readonly id: string;
  readonly von: string;
  readonly status: 'offen' | 'genehmigt' | 'abgelehnt';
}

Si tenant_id figure dans le type de ligne, le nom de table devient inassignable et l'appel échoue dès la compilation — le locataire, c'est la plateforme qui le pose.

Lire et écrire

// Lesen
await saims.db.from<Antrag>('antraege').orderBy('von', 'desc').selectAll();
await saims.db.from<Antrag>('antraege').where({ status: 'offen' }).count();
await saims.db.from<Antrag>('antraege').where({ id }).first();

// Schreiben — tenant_id setzt die Plattform
const angelegt = await saims.db.insert<Antrag>('antraege', { von, bis });
angelegt.id;                                      // die vergebene Kennung
await saims.db.update<Antrag>('antraege', { status: 'genehmigt' }, { id });
await saims.db.remove<Antrag>('antraege', { id });

Comparaisons

Une valeur signifie l'égalité, null signifie IS NULL. Pour tout le reste, il y a des fonctions de comparaison issues de @saims/sdk (gt, gte, lt, lte, ne, oneOf, noneOf, contains, startsWith, isSet, isNull) :

.where({ von: lte(bis), bis: gte(von) })          // überlappende Zeiträume
.where({ status: oneOf(['offen', 'genehmigt']) }) // mehrere Zustände
.where({ grund: contains('urlaub') })             // ohne Rücksicht auf Groß/Klein
🧩

oneOf([]) ne trouve rien — pas tout. C'est ce qui rend correct un filtre « tous les états choisis ». contains échappe % et _ : qui cherche « 50 % » cherche « 50 % ».

Groupes OU, pages, calcul

// Oder-Gruppe (eine Ebene tief, nur beim Lesen)
.whereAny([{ name: contains(s) }, { email: contains(s) }])
// → … AND (name ILIKE … OR email ILIKE …)

// Seitenweise — EINE Abfrage, Gesamtzahl inklusive
const { zeilen, gesamt } = await saims.db.from<Eintrag>('eintraege')
  .orderBy('datum', 'desc').seite({ nummer: 3, groesse: 20 });

// In der Datenbank rechnen
.groupBy('projekt_id').aggregate({ minuten: 'sum', anzahl: 'count' });

La liste dans whereAny est le OU, l'objet isolé reste un ET. seite compte en une seule instruction (count(*) OVER ()) — deux requêtes pourraient diverger. aggregate ne connaît que sum, avg, min, max, count ; le calcul se fait dans la base de données, pas en chargeant chaque ligne.

Plusieurs écritures en une seule

const schritte = await saims.db.inEinemZug((zug) => {
  zug.insert('koepfe', { nummer: 4711 });
  zug.insertMany('positionen', zeilen);
  zug.update('vorlagen', { zuletzt: heute }, { id: vorlage });
});
const kopf = schritte[0]!.zeile as Kopf | null;

Tout ce qu'il contient passe entièrement ou pas du tout (au plus 100 étapes). On n'y lit pas — ce qui doit être lu est lu avant ; sinon tu construis une orchestration par-dessus une frontière qui sera plus tard un réseau.

🚫

Ce qui n'existe pas : pas de JOIN, pas de sous-requêtes, pas d'expressions libres dans aggregate. Qui a besoin de plus a un constat sur le SDK — signaler plutôt que contourner.

Rozdział 4 · Usługi

saims.db — baza danych

Nie SQL, lecz plan: platforma sprawdza każdy identyfikator i wiąże każdą wartość. Wymaga db:own-schema.

Nie piszesz SQL, lecz plan. Platforma sprawdza każdy identyfikator i wiąże każdą wartość — zastrzyku SQL nie ma. Typ wiersza opisuje tabelę, bez tenant_id:

interface Antrag {
  readonly id: string;
  readonly von: string;
  readonly status: 'offen' | 'genehmigt' | 'abgelehnt';
}

Jeśli w typie wiersza stoi tenant_id, nazwa tabeli staje się nieprzypisywalna, a wywołanie zawodzi już przy kompilacji — najemcę ustawia platforma.

Odczyt i zapis

// Lesen
await saims.db.from<Antrag>('antraege').orderBy('von', 'desc').selectAll();
await saims.db.from<Antrag>('antraege').where({ status: 'offen' }).count();
await saims.db.from<Antrag>('antraege').where({ id }).first();

// Schreiben — tenant_id setzt die Plattform
const angelegt = await saims.db.insert<Antrag>('antraege', { von, bis });
angelegt.id;                                      // die vergebene Kennung
await saims.db.update<Antrag>('antraege', { status: 'genehmigt' }, { id });
await saims.db.remove<Antrag>('antraege', { id });

Porównania

Pojedyncza wartość oznacza równość, null oznacza IS NULL. Na wszystko inne są funkcje porównujące z @saims/sdk (gt, gte, lt, lte, ne, oneOf, noneOf, contains, startsWith, isSet, isNull):

.where({ von: lte(bis), bis: gte(von) })          // überlappende Zeiträume
.where({ status: oneOf(['offen', 'genehmigt']) }) // mehrere Zustände
.where({ grund: contains('urlaub') })             // ohne Rücksicht auf Groß/Klein
🧩

oneOf([]) nie znajduje nic — nie wszystko. To sprawia, że filtr „wszystkie wybrane stany" jest poprawny. contains maskuje % i _: kto szuka „50 %", szuka „50 %".

Grupy „lub", strony, liczenie

// Oder-Gruppe (eine Ebene tief, nur beim Lesen)
.whereAny([{ name: contains(s) }, { email: contains(s) }])
// → … AND (name ILIKE … OR email ILIKE …)

// Seitenweise — EINE Abfrage, Gesamtzahl inklusive
const { zeilen, gesamt } = await saims.db.from<Eintrag>('eintraege')
  .orderBy('datum', 'desc').seite({ nummer: 3, groesse: 20 });

// In der Datenbank rechnen
.groupBy('projekt_id').aggregate({ minuten: 'sum', anzahl: 'count' });

Lista w whereAny jest tym lub, pojedynczy obiekt pozostaje tym i. seite liczy w jednej instrukcji (count(*) OVER ()) — dwa zapytania mogłyby się rozejść. aggregate zna tylko sum, avg, min, max, count; liczy się w bazie danych, a nie przez ładowanie każdego wiersza.

Wiele zapisów jako jeden

const schritte = await saims.db.inEinemZug((zug) => {
  zug.insert('koepfe', { nummer: 4711 });
  zug.insertMany('positionen', zeilen);
  zug.update('vorlagen', { zuletzt: heute }, { id: vorlage });
});
const kopf = schritte[0]!.zeile as Kopf | null;

Wszystko w tym bloku przechodzi w całości albo wcale (najwyżej 100 kroków). Odczytu w nim nie ma — co trzeba odczytać, odczytuje się wcześniej; inaczej budujesz sterowanie przebiegiem przez granicę, która później jest siecią.

🚫

Czego nie ma: żadnego JOIN, żadnych podzapytań, żadnych swobodnych wyrażeń w aggregate. Kto potrzebuje więcej, ma ustalenie dotyczące SDK — zgłaszaj zamiast obchodzić.

Capitolo 4 · I servizi

saims.db — il database

Non SQL, ma un progetto: la piattaforma verifica ogni identificatore e lega ogni valore. Presuppone db:own-schema.

Non scrivi SQL, ma un progetto. La piattaforma verifica ogni identificatore e lega ogni valore — la SQL injection non esiste. Il tipo di riga descrive la tabella, senza tenant_id:

interface Antrag {
  readonly id: string;
  readonly von: string;
  readonly status: 'offen' | 'genehmigt' | 'abgelehnt';
}

Se tenant_id sta nel tipo di riga, il nome della tabella diventa non assegnabile e la chiamata fallisce già alla compilazione — il tenant lo imposta la piattaforma.

Leggere e scrivere

// Lesen
await saims.db.from<Antrag>('antraege').orderBy('von', 'desc').selectAll();
await saims.db.from<Antrag>('antraege').where({ status: 'offen' }).count();
await saims.db.from<Antrag>('antraege').where({ id }).first();

// Schreiben — tenant_id setzt die Plattform
const angelegt = await saims.db.insert<Antrag>('antraege', { von, bis });
angelegt.id;                                      // die vergebene Kennung
await saims.db.update<Antrag>('antraege', { status: 'genehmigt' }, { id });
await saims.db.remove<Antrag>('antraege', { id });

Confronti

Un valore significa uguaglianza, null significa IS NULL. Per tutto il resto ci sono funzioni di confronto da @saims/sdk (gt, gte, lt, lte, ne, oneOf, noneOf, contains, startsWith, isSet, isNull):

.where({ von: lte(bis), bis: gte(von) })          // überlappende Zeiträume
.where({ status: oneOf(['offen', 'genehmigt']) }) // mehrere Zustände
.where({ grund: contains('urlaub') })             // ohne Rücksicht auf Groß/Klein
🧩

oneOf([]) non trova nulla — non tutto. Questo rende corretto un filtro "tutti gli stati selezionati". contains fa l'escape di % e _: chi cerca "50 %" cerca "50 %".

Gruppi O, pagine, calcolo

// Oder-Gruppe (eine Ebene tief, nur beim Lesen)
.whereAny([{ name: contains(s) }, { email: contains(s) }])
// → … AND (name ILIKE … OR email ILIKE …)

// Seitenweise — EINE Abfrage, Gesamtzahl inklusive
const { zeilen, gesamt } = await saims.db.from<Eintrag>('eintraege')
  .orderBy('datum', 'desc').seite({ nummer: 3, groesse: 20 });

// In der Datenbank rechnen
.groupBy('projekt_id').aggregate({ minuten: 'sum', anzahl: 'count' });

La lista in whereAny è l'O, il singolo oggetto resta un E. seite conta in una istruzione (count(*) OVER ()) — due query potrebbero divergere. aggregate conosce solo sum, avg, min, max, count; il calcolo avviene nel database, non caricando ogni riga.

Più scritture come una sola

const schritte = await saims.db.inEinemZug((zug) => {
  zug.insert('koepfe', { nummer: 4711 });
  zug.insertMany('positionen', zeilen);
  zug.update('vorlagen', { zuletzt: heute }, { id: vorlage });
});
const kopf = schritte[0]!.zeile as Kopf | null;

Tutto ciò che vi è contenuto passa interamente o per niente (al massimo 100 passi). Al suo interno non si legge — ciò che va letto va letto prima; altrimenti costruisci un controllo di flusso attraverso un confine che in seguito è una rete.

🚫

Che cosa non esiste: nessun JOIN, nessuna sottoquery, nessuna espressione libera in aggregate. Chi ha bisogno di più ha un rilievo sull'SDK — segnalare invece di aggirare.

Hoofdstuk 4 · De diensten

saims.db — de database

Geen SQL, maar een bouwplan: Het platform controleert elke identifier en bindt elke waarde. Vereist db:own-schema.

Je schrijft geen SQL, maar een bouwplan. Het platform controleert elke identifier en bindt elke waarde — SQL-injectie bestaat niet. Het rijtype beschrijft de tabel, zonder tenant_id:

interface Antrag {
  readonly id: string;
  readonly von: string;
  readonly status: 'offen' | 'genehmigt' | 'abgelehnt';
}

Staat tenant_id in het rijtype, dan wordt de tabelnaam niet-toewijsbaar en faalt de aanroep al bij het compileren — de tenant stelt het platform in.

Lezen en schrijven

// Lesen
await saims.db.from<Antrag>('antraege').orderBy('von', 'desc').selectAll();
await saims.db.from<Antrag>('antraege').where({ status: 'offen' }).count();
await saims.db.from<Antrag>('antraege').where({ id }).first();

// Schreiben — tenant_id setzt die Plattform
const angelegt = await saims.db.insert<Antrag>('antraege', { von, bis });
angelegt.id;                                      // die vergebene Kennung
await saims.db.update<Antrag>('antraege', { status: 'genehmigt' }, { id });
await saims.db.remove<Antrag>('antraege', { id });

Vergelijkingen

Eén waarde betekent gelijkheid, null betekent IS NULL. Voor al het andere zijn er vergelijkingsfuncties uit @saims/sdk (gt, gte, lt, lte, ne, oneOf, noneOf, contains, startsWith, isSet, isNull):

.where({ von: lte(bis), bis: gte(von) })          // überlappende Zeiträume
.where({ status: oneOf(['offen', 'genehmigt']) }) // mehrere Zustände
.where({ grund: contains('urlaub') })             // ohne Rücksicht auf Groß/Klein
🧩

oneOf([]) vindt niets — niet alles. Dat maakt een filter „alle gekozen toestanden" juist. contains maskeert % en _: Wie naar „50 %" zoekt, zoekt naar „50 %".

Of-groepen, pagina's, rekenen

// Oder-Gruppe (eine Ebene tief, nur beim Lesen)
.whereAny([{ name: contains(s) }, { email: contains(s) }])
// → … AND (name ILIKE … OR email ILIKE …)

// Seitenweise — EINE Abfrage, Gesamtzahl inklusive
const { zeilen, gesamt } = await saims.db.from<Eintrag>('eintraege')
  .orderBy('datum', 'desc').seite({ nummer: 3, groesse: 20 });

// In der Datenbank rechnen
.groupBy('projekt_id').aggregate({ minuten: 'sum', anzahl: 'count' });

De lijst in whereAny is het of, het afzonderlijke object blijft een en. seite telt in één instructie (count(*) OVER ()) — twee query's zouden uiteen kunnen lopen. aggregate kent alleen sum, avg, min, max, count; er wordt gerekend in de database, niet door elke rij te laden.

Meerdere schrijfacties als één

const schritte = await saims.db.inEinemZug((zug) => {
  zug.insert('koepfe', { nummer: 4711 });
  zug.insertMany('positionen', zeilen);
  zug.update('vorlagen', { zuletzt: heute }, { id: vorlage });
});
const kopf = schritte[0]!.zeile as Kopf | null;

Alles daarin gaat helemaal door of helemaal niet (maximaal 100 stappen). Er wordt daarin niet gelezen — wat gelezen moet worden, wordt vooraf gelezen; anders bouw je een procesbesturing over een grens die later een netwerk is.

🚫

Wat er niet is: geen JOIN, geen subquery's, geen vrije expressies in aggregate. Wie meer nodig heeft, heeft een bevinding over de SDK — melden in plaats van omzeilen.

Capitolul 4 · Serviciile

saims.db — baza de date

Niciun SQL, ci un plan de construcție: Platforma verifică fiecare identificator și leagă fiecare valoare. Presupune db:own-schema.

Nu scrii SQL, ci un plan de construcție. Platforma verifică fiecare identificator și leagă fiecare valoare — injecția SQL nu există. Tipul de rând descrie tabela, fără tenant_id:

interface Antrag {
  readonly id: string;
  readonly von: string;
  readonly status: 'offen' | 'genehmigt' | 'abgelehnt';
}

Dacă tenant_id stă în tipul de rând, numele tabelei devine neatribuibil și apelul eșuează deja la compilare — tenantul îl setează platforma.

Citire și scriere

// Lesen
await saims.db.from<Antrag>('antraege').orderBy('von', 'desc').selectAll();
await saims.db.from<Antrag>('antraege').where({ status: 'offen' }).count();
await saims.db.from<Antrag>('antraege').where({ id }).first();

// Schreiben — tenant_id setzt die Plattform
const angelegt = await saims.db.insert<Antrag>('antraege', { von, bis });
angelegt.id;                                      // die vergebene Kennung
await saims.db.update<Antrag>('antraege', { status: 'genehmigt' }, { id });
await saims.db.remove<Antrag>('antraege', { id });

Comparații

O valoare înseamnă egalitate, null înseamnă IS NULL. Pentru orice altceva există funcții de comparație din @saims/sdk (gt, gte, lt, lte, ne, oneOf, noneOf, contains, startsWith, isSet, isNull):

.where({ von: lte(bis), bis: gte(von) })          // überlappende Zeiträume
.where({ status: oneOf(['offen', 'genehmigt']) }) // mehrere Zustände
.where({ grund: contains('urlaub') })             // ohne Rücksicht auf Groß/Klein
🧩

oneOf([]) nu găsește nimic — nu tot. Asta face corect un filtru „toate stările alese". contains maschează % și _: Cine caută „50 %" caută „50 %".

Grupuri-sau, pagini, calcul

// Oder-Gruppe (eine Ebene tief, nur beim Lesen)
.whereAny([{ name: contains(s) }, { email: contains(s) }])
// → … AND (name ILIKE … OR email ILIKE …)

// Seitenweise — EINE Abfrage, Gesamtzahl inklusive
const { zeilen, gesamt } = await saims.db.from<Eintrag>('eintraege')
  .orderBy('datum', 'desc').seite({ nummer: 3, groesse: 20 });

// In der Datenbank rechnen
.groupBy('projekt_id').aggregate({ minuten: 'sum', anzahl: 'count' });

Lista din whereAny este sau-ul, obiectul individual rămâne un și. seite numără într-o singură instrucțiune (count(*) OVER ()) — două interogări ar putea diverge. aggregate cunoaște doar sum, avg, min, max, count; se calculează în baza de date, nu prin încărcarea fiecărui rând.

Mai multe scrieri ca una singură

const schritte = await saims.db.inEinemZug((zug) => {
  zug.insert('koepfe', { nummer: 4711 });
  zug.insertMany('positionen', zeilen);
  zug.update('vorlagen', { zuletzt: heute }, { id: vorlage });
});
const kopf = schritte[0]!.zeile as Kopf | null;

Tot ce e înăuntru trece în întregime sau deloc (cel mult 100 de pași). Înăuntru nu se citește — ce trebuie citit se citește înainte; altfel construiești o logică de desfășurare peste o graniță care mai târziu este o rețea.

🚫

Ce nu există: niciun JOIN, nicio subinterogare, nicio expresie liberă în aggregate. Cine are nevoie de mai mult are un constat despre SDK — raportează în loc să ocolești.

Κεφάλαιο 4 · Οι υπηρεσίες

saims.db — η βάση δεδομένων

Όχι SQL, αλλά ένα σχέδιο δόμησης: η πλατφόρμα ελέγχει κάθε αναγνωριστικό και δεσμεύει κάθε τιμή. Προϋποθέτει db:own-schema.

Δεν γράφεις SQL, αλλά ένα σχέδιο δόμησης. Η πλατφόρμα ελέγχει κάθε αναγνωριστικό και δεσμεύει κάθε τιμή — SQL injection δεν υπάρχει. Ο τύπος της γραμμής περιγράφει τον πίνακα, χωρίς tenant_id:

interface Antrag {
  readonly id: string;
  readonly von: string;
  readonly status: 'offen' | 'genehmigt' | 'abgelehnt';
}

Αν το tenant_id βρίσκεται στον τύπο της γραμμής, το όνομα του πίνακα γίνεται μη αναθέσιμο και η κλήση αποτυγχάνει ήδη κατά τη μεταγλώττιση — τον μισθωτή τον ορίζει η πλατφόρμα.

Ανάγνωση και εγγραφή

// Lesen
await saims.db.from<Antrag>('antraege').orderBy('von', 'desc').selectAll();
await saims.db.from<Antrag>('antraege').where({ status: 'offen' }).count();
await saims.db.from<Antrag>('antraege').where({ id }).first();

// Schreiben — tenant_id setzt die Plattform
const angelegt = await saims.db.insert<Antrag>('antraege', { von, bis });
angelegt.id;                                      // die vergebene Kennung
await saims.db.update<Antrag>('antraege', { status: 'genehmigt' }, { id });
await saims.db.remove<Antrag>('antraege', { id });

Συγκρίσεις

Μια τιμή σημαίνει ισότητα, το null σημαίνει IS NULL. Για όλα τα υπόλοιπα υπάρχουν συναρτήσεις σύγκρισης από το @saims/sdk (gt, gte, lt, lte, ne, oneOf, noneOf, contains, startsWith, isSet, isNull):

.where({ von: lte(bis), bis: gte(von) })          // überlappende Zeiträume
.where({ status: oneOf(['offen', 'genehmigt']) }) // mehrere Zustände
.where({ grund: contains('urlaub') })             // ohne Rücksicht auf Groß/Klein
🧩

Το oneOf([]) δεν βρίσκει τίποτα — όχι τα πάντα. Αυτό κάνει σωστό ένα φίλτρο „όλες οι επιλεγμένες καταστάσεις". Το contains χαρακτηρίζει με escape το % και το _: όποιος ψάχνει „50 %", ψάχνει „50 %".

Ομάδες-Ή, σελίδες, υπολογισμοί

// Oder-Gruppe (eine Ebene tief, nur beim Lesen)
.whereAny([{ name: contains(s) }, { email: contains(s) }])
// → … AND (name ILIKE … OR email ILIKE …)

// Seitenweise — EINE Abfrage, Gesamtzahl inklusive
const { zeilen, gesamt } = await saims.db.from<Eintrag>('eintraege')
  .orderBy('datum', 'desc').seite({ nummer: 3, groesse: 20 });

// In der Datenbank rechnen
.groupBy('projekt_id').aggregate({ minuten: 'sum', anzahl: 'count' });

Η λίστα στο whereAny είναι το Ή, το μεμονωμένο αντικείμενο παραμένει ένα Και. Το seite μετρά σε μία εντολή (count(*) OVER ()) — δύο ερωτήματα θα μπορούσαν να αποκλίνουν. Το aggregate γνωρίζει μόνο sum, avg, min, max, count· ο υπολογισμός γίνεται στη βάση δεδομένων, όχι με φόρτωση κάθε γραμμής.

Πολλές εγγραφές ως μία

const schritte = await saims.db.inEinemZug((zug) => {
  zug.insert('koepfe', { nummer: 4711 });
  zug.insertMany('positionen', zeilen);
  zug.update('vorlagen', { zuletzt: heute }, { id: vorlage });
});
const kopf = schritte[0]!.zeile as Kopf | null;

Ό,τι περιέχεται εκεί μέσα περνά ολόκληρο ή καθόλου (το πολύ 100 βήματα). Ανάγνωση εκεί μέσα δεν γίνεται — ό,τι πρέπει να διαβαστεί, διαβάζεται πρώτα· διαφορετικά χτίζεις έναν έλεγχο ροής πάνω από ένα όριο που αργότερα γίνεται δίκτυο.

🚫

Τι δεν υπάρχει: κανένα JOIN, κανένα υποερώτημα, καμία ελεύθερη έκφραση στο aggregate. Όποιος χρειάζεται περισσότερα, έχει ένα εύρημα σχετικά με το SDK — ανάφερέ το αντί να το παρακάμψεις.

الفصل 4 · الخدمات

saims.db — قاعدة البيانات

لا SQL، بل مخطّط بناء: المنصّة تتحقّق من كل مُعرِّف وتربط كل قيمة. يشترط db:own-schema.

أنت لا تكتب SQL، بل مخطّط بناء. المنصّة تتحقّق من كل مُعرِّف وتربط كل قيمة — فحقن SQL غير وارد. ونوع الصفّ يصف الجدول، دون tenant_id:

interface Antrag {
  readonly id: string;
  readonly von: string;
  readonly status: 'offen' | 'genehmigt' | 'abgelehnt';
}

إذا وُجد tenant_id في نوع الصفّ، صار اسم الجدول غير قابل للإسناد وفشل الاستدعاء منذ الترجمة — فالمستأجر تضبطه المنصّة.

القراءة والكتابة

// Lesen
await saims.db.from<Antrag>('antraege').orderBy('von', 'desc').selectAll();
await saims.db.from<Antrag>('antraege').where({ status: 'offen' }).count();
await saims.db.from<Antrag>('antraege').where({ id }).first();

// Schreiben — tenant_id setzt die Plattform
const angelegt = await saims.db.insert<Antrag>('antraege', { von, bis });
angelegt.id;                                      // die vergebene Kennung
await saims.db.update<Antrag>('antraege', { status: 'genehmigt' }, { id });
await saims.db.remove<Antrag>('antraege', { id });

المقارنات

قيمةٌ تعني مساواة، وnull تعني IS NULL. ولكل ما عدا ذلك توجد دوال مقارنة من @saims/sdk (gt, gte, lt, lte, ne, oneOf, noneOf, contains, startsWith, isSet, isNull):

.where({ von: lte(bis), bis: gte(von) })          // überlappende Zeiträume
.where({ status: oneOf(['offen', 'genehmigt']) }) // mehrere Zustände
.where({ grund: contains('urlaub') })             // ohne Rücksicht auf Groß/Klein
🧩

oneOf([]) لا يجد شيئًا — لا كلّ شيء. وهذا ما يجعل مرشّح „كل الحالات المختارة" صحيحًا. contains يُهرِّب % و_: فمن يبحث عن „50 %" يبحث عن „50 %".

مجموعات Oder، الصفحات، الحساب

// Oder-Gruppe (eine Ebene tief, nur beim Lesen)
.whereAny([{ name: contains(s) }, { email: contains(s) }])
// → … AND (name ILIKE … OR email ILIKE …)

// Seitenweise — EINE Abfrage, Gesamtzahl inklusive
const { zeilen, gesamt } = await saims.db.from<Eintrag>('eintraege')
  .orderBy('datum', 'desc').seite({ nummer: 3, groesse: 20 });

// In der Datenbank rechnen
.groupBy('projekt_id').aggregate({ minuten: 'sum', anzahl: 'count' });

القائمة في whereAny هي الـ Oder (أو)، أمّا الكائن المفرد فيبقى Und (و). seite يَعُدّ في عبارة واحدة (count(*) OVER ()) — فاستعلامان قد يتباعدان. aggregate لا يعرف سوى sum, avg, min, max, count؛ والحساب يجري في قاعدة البيانات، لا بتحميل كل صفّ.

عدّة عمليات كتابة كعملية واحدة

const schritte = await saims.db.inEinemZug((zug) => {
  zug.insert('koepfe', { nummer: 4711 });
  zug.insertMany('positionen', zeilen);
  zug.update('vorlagen', { zuletzt: heute }, { id: vorlage });
});
const kopf = schritte[0]!.zeile as Kopf | null;

كل ما بداخله يمرّ كاملًا أو لا يمرّ البتّة (100 خطوة كحدّ أقصى). ولا تُجرى قراءة بداخله — فما يجب قراءته يُقرأ قبلئذٍ؛ وإلا فأنت تبني تحكّمًا في التدفّق عبر حدٍّ سيصير لاحقًا شبكة.

🚫

ما هو غير موجود: لا JOIN، ولا استعلامات فرعية، ولا تعابير حرّة في aggregate. من يحتاج أكثر، فلديه اكتشاف يخصّ الـ SDK — الإبلاغ بدل الالتفاف.

第 4 章 · 服务

saims.db——数据库

不是 SQL,而是一份蓝图:平台检查每一个标识符并绑定每一个值。以 db:own-schema 为前提。

你写的不是 SQL,而是一份蓝图。平台检查每一个标识符并绑定每一个值——不存在 SQL 注入。行类型描述表,不含 tenant_id:

interface Antrag {
  readonly id: string;
  readonly von: string;
  readonly status: 'offen' | 'genehmigt' | 'abgelehnt';
}

如果 tenant_id 出现在行类型里,表名就变得无法赋值,调用在编译时就会失败——租户由平台设置。

读取和写入

// Lesen
await saims.db.from<Antrag>('antraege').orderBy('von', 'desc').selectAll();
await saims.db.from<Antrag>('antraege').where({ status: 'offen' }).count();
await saims.db.from<Antrag>('antraege').where({ id }).first();

// Schreiben — tenant_id setzt die Plattform
const angelegt = await saims.db.insert<Antrag>('antraege', { von, bis });
angelegt.id;                                      // die vergebene Kennung
await saims.db.update<Antrag>('antraege', { status: 'genehmigt' }, { id });
await saims.db.remove<Antrag>('antraege', { id });

比较

一个值表示相等,null 表示 IS NULL。其余一切都有来自 @saims/sdk 的比较函数(gt, gte, lt, lte, ne, oneOf, noneOf, contains, startsWith, isSet, isNull):

.where({ von: lte(bis), bis: gte(von) })          // überlappende Zeiträume
.where({ status: oneOf(['offen', 'genehmigt']) }) // mehrere Zustände
.where({ grund: contains('urlaub') })             // ohne Rücksicht auf Groß/Klein
🧩

oneOf([]) 什么都找不到——而不是找到一切。这让一个“所有已选状态”的过滤器变得正确。contains 会转义 % 和 _:搜索“50 %”的人,搜的就是“50 %”。

或组、分页、计算

// Oder-Gruppe (eine Ebene tief, nur beim Lesen)
.whereAny([{ name: contains(s) }, { email: contains(s) }])
// → … AND (name ILIKE … OR email ILIKE …)

// Seitenweise — EINE Abfrage, Gesamtzahl inklusive
const { zeilen, gesamt } = await saims.db.from<Eintrag>('eintraege')
  .orderBy('datum', 'desc').seite({ nummer: 3, groesse: 20 });

// In der Datenbank rechnen
.groupBy('projekt_id').aggregate({ minuten: 'sum', anzahl: 'count' });

whereAny 中的列表是或,单个对象仍然是且。seite 在一条语句里计数(count(*) OVER ())——两次查询可能会对不上。aggregate 只认识 sum, avg, min, max, count;计算在数据库里完成,而不是靠加载每一行。

把多次写入当作一次

const schritte = await saims.db.inEinemZug((zug) => {
  zug.insert('koepfe', { nummer: 4711 });
  zug.insertMany('positionen', zeilen);
  zug.update('vorlagen', { zuletzt: heute }, { id: vorlage });
});
const kopf = schritte[0]!.zeile as Kopf | null;

其中的一切要么整体成功,要么全不成功(最多 100 步)。其中不进行读取——需要读取的,事先读取;否则你就在一条日后是网络的边界上搭建了一套流程控制。

🚫

有哪些东西不存在:没有 JOIN,没有子查询,aggregate 里没有自由表达式。需要更多的人,有一个关于 SDK 的发现——上报而非绕开。