Skip to content

feat: support object tables instead of rest array in orm #17

@sandros94

Description

@sandros94

Love to see this project shaping up, would it be possible to improve its DX for passing the schema to orm?

As of now we are forced to pass tables as rest param:

const db = orm(new Surreal(), user, post, authored);

but wouldn't it be more simple to have them as object instead?

Like:

const db = orm(new Surreal(), {
  user,
  post,
  authored,
});

This could also unlock the ability to define all the tables in a unified place and then import them via alias while keeping full type support:

// database/schema.ts
import { table, t, edge } from "surqlize";

export const user = table("user", {
  name: t.string(),
  email: t.string(),
});

export const post = table("post", {
  title: t.string(),
  content: t.string(),
});

export const authored = edge("user", "authored", "post", {
  created: t.date(),
  role: t.union([t.literal("author"), t.literal("co-author")]),
});
// src/surqlize.ts
import * as schema from '../database/schema.ts'

const db = orm(new Surreal(), schema);

This would greatly benefit rapid reuse of separate orm that might share all or part of the schema

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions