vormi

0.1.3 • Public • Published

VORMi

VORMi, developed by VOID, is an innovative Object Relational Mapping Interface designed to enhance your development experience with powerful ORM capabilities, complemented by IntelliSense and type safety across your entire database schema.

Features

  • Type Safety: Ensure your database interactions are safe and predictable with TypeScript's type safety. AKA, non-existent tables or columns will be caught while you write your code, not at runtime.
  • IntelliSense Support: Boost your productivity with auto-completion for your own tables and columns that were statically defined in your VORMi schema.
  • Self-Creating Schema: Whenever VORMi encounters an internal error of a table or column not existing, it will automatically create the table or column in the database for you, as long as it is defined in the schema, and then it will retry the operation.
  • Adapter Support: Extend VORMi with different storage adapters, including a built-in memory adapter for quick testing and prototyping.

Installation

To get started with VORMi, install the package via npm by running the following command in your terminal:

npm install vormi

Quick Start

Define your data models using a simple Typescript object:

const schema = {
    user: {
        id: C.int().autoIncrement().primaryKey(),
        uid: C.binary(16).unique().index(),
        display_name: C.varchar(64),
        email: C.varchar(255),
        age: C.int().nullable(),
        created: C.datetime().default('now'),
        updated: C.datetime().default('now').onUpdate('now'),
        banned: C.boolean().default(false)
    },
    post: {
        id: C.int().autoIncrement().primaryKey(),
        user_id: C.int().references('user', 'id'),
        content: C.text()
    },
    comment: {
        id: C.int().autoIncrement().primaryKey(),
        post_id: C.int().references('post', 'id'),
        user_id: C.int().references('user', 'id'),
        content: C.text()
    }
};

C is a shorthand for Column and is used to define the columns of a table. The Column class provides a variety of methods to define the column's properties, such as autoIncrement, primaryKey, unique, index, references, default, nullable, and onUpdate.

The method-chaining schema syntax allows you to define the column's properties in a fluent and readable manner, utilizing the horizontal space efficiently, without polluting the code vertically with unnecessary line breaks like in other types of ORM libraries. This gives you an efficient bird's eye view of the whole database schema in a single glance, which is especially useful when working with large schemas.

Now prepare your VORMi instance with the database schema you just created and an adapter to interact with the database of your choice. We'll use the built-in MemoryAdapter for this example:

import { VDatabase, MemoryAdapter } from 'vormi';

// Create a database instance with the schema.
const db = new VDatabase(schema, new MemoryAdapter());

Leverage TypeScript's IntelliSense for type-safe database operations:

// Insert a new user into the 'user' table
await db.from('user').insert({ display_name: 'John Doe', age: 25, banned: false, created: new Date(), updated: new Date() });
// Select all rows from the 'user' table with the 'id' and 'display_name' columns only
const result = await db.from('user').fields('id', 'display_name').all();
// Get the first row from the result
const user = result.rows[0];
// Output the result
console.log(user);
// Outputs: { id: 1, display_name: "John Doe" }

Adapters

VORMi is designed to be extensible with various storage solutions. Currently supported adapters include:

  • MemoryAdapter for in-memory databases, perfect for testing and development environments.

(Additional adapter documentation and examples to be added as they become available.)

Contributing

We welcome contributions to VORMi! Whether you're interested in fixing bugs, adding new features, or improving documentation, please feel free to make a pull request or open an issue.

License

VORMi is MIT licensed.

Package Sidebar

Install

npm i vormi

Weekly Downloads

4

Version

0.1.3

License

MIT

Unpacked Size

38.1 kB

Total Files

23

Last publish

Collaborators

  • beyondo