npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

treevial_orm

v0.0.7

Published

ORM for surrealdb

Readme

Note

check out Lucid here

Key Features

  • Define Schemas, with fields and relationships as well as indexes and constraints
  • Sync Data model (though basic atm), renames, adds, drops, etc.
  • Flexible with data types, supports all of SurrealDB's data types and a Prisma-like query builder
  • Fully typesafe, easily infer your data model when doing a simple select or a more complex count or boolean query
  • SELECT, DELETE, DELETE MANY, CREATE, CREATE MANY
  • Framework agnostic, use it with any framework
  • Easily handle recursive relationships without any hassle of circular references
  • And a lot more

How To Use

To clone and run this application, you'll need Git and Node.js

# Clone this repository
$ git clone [email protected]:soya-miruku/Treevial.git

# Go into the repository
$ cd Treevial

# Install dependencies
$ bun install

# Run the tests
$ bun run src/tests

Usage

import { AdapterFactory, inferFull Treevial } from './surreal';

// first we will need to define a model, currently we can use the MultiDef class to do so (ideally it would be good to have a Define class which would be used to define a single model)

const schemas = Treevial.MultiDef(({ number, string, date, array, record, relation, object, enums }) => ({
  User: {
    id: string(), //ideally we should have an id type
    name: string(),
    email: string({ required: true, index: 'idx_user_email' }),
    password: string(),
    createdOn: date({ required: false, default: () => new Date() }),
    updatedAt: date(),
    posts: array(record(() => schemas.defs.post)),
    following: relation({
      edge: object({
        createdAt: date({ default: () => new Date() }),
        how: enums(['post', 'search'], { required: true }),
      }),
      out: object(() => schemas.defs.user),
      name: 'follows',
      inverse: false,
    }),
    followers: relation({
      edge: object({ createdAt: date({ default: () => new Date() }), how: enums(['post', 'search']) }),
      out: object(() => schemas.defs.user),
      name: 'follows',
      inverse: true,
    }),
  },
  Post: {
    id: string({ required: true }),
    createdOn: date({ required: false }),
    content: string({ required: false }),
  },
});

// if you want to infer the basic type/ full type of a model you can use the inferFull function or the inferBasic function and there are also a few more
type User = inferFull<typeof schemas.defined.user>;

// initialise the client (still need to work on creating a proper connection)
schemas.initialize();
const adapter = AdapterFactory.Create({
  type: 'surreal',
  auth: {
    username: 'root',
    password: 'root',
    port: 8000,
    host: '127.0.0.1',
    database: 'ttest',
    namespace: 'ttest',
  },
});

const client = await adapter.Connect({ ...schemas.defined }); //creates the client with all the schemas

// now we can use the client to do queries or whatever else, if you are familiar with Prisma, this works alot like that
--------------------------------------------
// FIND MANY
const user = await client.User.FindMany({
  select: {
    id: true,
    name: true,
    email: true,
    posts: {
      _count: true,
      as: 'postCount',
    },
    following: {
      _count: true,
      as: 'followingCount',
    },
  },
  where: {
    age: { gt: 10 },
  }
})

--------------------------------------------
// CREATE
const user = await client.User.Create({
  data: {
    name: 'myname',
    email: '[email protected]',
  }
}) // fields marked as required will be (...well) required XD

You may also like...

  • Lucid - A full fledged ORM for SurrealDB

License

MIT


GitHub @soya-miruku