db

Generated by tinox doc

A minimal Panache-style ORM stub: DB.of(EntityClass) starts a compile-time-intercepted query chain (filter/orderBy/limit/save/delete) over classes annotated @Entity. All chain methods are rewritten by the codegen, not executed as ordinary Tinox calls.

Entity crud

// tinox enforces one type per file, so this is really two files in a
// real project: Customer.tnx (below) and Main.tnx (`import Customer;`
// alongside `import tinox.core.db;`) — combined here for readability.

import tinox.core.db;

@Entity
@Table("customers")
class Customer
{
    @Id
    @GeneratedValue
    var id: Int64;

    var name: String;
    var email: String;
}

class Main
{
    fnc main() -> Int32
    {
        let customers: List<Customer> = DB.of(Customer).list();

        let customer: Customer = DB.of(Customer).filter(c => c.id == 1).first();
        println(customer.name);

        let active: List<Customer> = DB.of(Customer).orderBy(c => c.name).limit(10).list();

        DB.of(Customer).save(customer);
        DB.of(Customer).delete(customer);

        return 0;
    }
}

class DB

Methods

fnc of(cls: Any) → Any

class EntityQuery

Methods

fn filter(predicate: fn(Any) -> Bool) → Any
fn orderBy(field: fn(Any) -> Any) → Any
fn orderByDesc(field: fn(Any) -> Any) → Any
fn limit(n: Int64) → Any
fn offset(n: Int64) → Any
fn list() → Any
fn first() → Any
fn count() → Int64
fn save(entity: Any) → Any
fn delete(entity: Any) → Nothing
fn saveAll(entities: Any) → Nothing