-
Notifications
You must be signed in to change notification settings - Fork 0
Schema
Carlos Lopez edited this page Jul 16, 2026
·
1 revision
Documentación completa sobre cómo definir esquemas de entidades.
Define una entidad con su nombre y columnas.
import { entity, uuid, text, int } from '@kettu/gitdb';
const User = entity('users', {
id: uuid().primary(),
name: text(),
age: int()
});Texto ilimitado. Ideal para descripciones y contenido largo.
const description = text();Texto con límite opcional de caracteres.
const username = varchar(50);
const email = varchar(255);Texto de longitud fija (rellena con espacios).
const code = char(10);Entero de 32 bits. Rango: -2,147,483,648 a 2,147,483,647
const age = int();
const score = integer();Entero de 64 bits. Para números muy grandes.
const largeNumber = bigint();Decimal de precisión arbitraria. Ideal para dinero.
const price = numeric(10, 2); // 10 dígitos, 2 decimales
const salary = numeric(15, 2);Números decimales de punto flotante.
const height = real();
const weight = double();
const temperature = doublePrecision();Valores verdadero/falso.
const isActive = bool();
const isAdmin = boolean();Solo la fecha, sin hora.
const birthDate = date();
const createdDate = date();Fecha y hora completa (ISO 8601).
const createdAt = timestamp();
const updatedAt = timestamp();
const deletedAt = timestamp(); // Para soft deletesUUID/GUID único. Ideal para IDs distribuidos.
const id = uuid().primary();Objeto JSON. Permite estructura flexible.
const metadata = json();
const config = json();const id = uuid().primary();
const userId = int().primary();const email = text().unique();
const username = varchar(50).unique();import {
entity,
uuid,
text,
varchar,
int,
numeric,
timestamp,
bool,
json
} from '@kettu/gitdb';
export const User = entity('users', {
id: uuid().primary(),
email: text().unique(),
username: varchar(50).unique(),
firstName: text(),
lastName: text(),
age: int(),
isActive: bool(),
metadata: json(),
createdAt: timestamp(),
updatedAt: timestamp()
});
export const Product = entity('products', {
id: uuid().primary(),
sku: varchar(20).unique(),
name: text(),
description: text(),
price: numeric(10, 2),
stock: int(),
rating: real(),
tags: json(),
createdAt: timestamp()
});