0.4.3 • Published 10 months ago

vormi v0.4.3

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

VORMi

VORMi stands for VOID Object Relational Mapping Interface that was developed by VOID Operations to be a lightweight, type-safe, and self-creating ORM library for Node.js and TypeScript. In order to ensure type-safety, VORMi will assume the schema you provide is the only schema that exists in the database, and it will automatically create tables and columns that are not found.

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:

import { C } from 'vormi';

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 it has a variety of methods to define a column's properties as seen in this code. The method-chaining schema syntax 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 database schemas, unlike other ORM libraries that use a more JSON-like syntax.

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.

0.2.20

10 months ago

0.2.19

10 months ago

0.2.18

10 months ago

0.2.17

10 months ago

0.2.16

10 months ago

0.2.15

10 months ago

0.2.14

10 months ago

0.2.13

10 months ago

0.2.12

10 months ago

0.2.11

10 months ago

0.3.0

10 months ago

0.3.6

10 months ago

0.3.8

10 months ago

0.3.7

10 months ago

0.3.2

10 months ago

0.3.1

10 months ago

0.3.4

10 months ago

0.3.3

10 months ago

0.4.1

10 months ago

0.4.0

10 months ago

0.4.3

10 months ago

0.4.2

10 months ago

0.3.31

10 months ago

0.3.30

10 months ago

0.3.35

10 months ago

0.3.34

10 months ago

0.3.33

10 months ago

0.3.32

10 months ago

0.3.29

10 months ago

0.3.20

10 months ago

0.3.28

10 months ago

0.3.27

10 months ago

0.3.26

10 months ago

0.3.25

10 months ago

0.3.24

10 months ago

0.3.23

10 months ago

0.3.22

10 months ago

0.3.21

10 months ago

0.3.19

10 months ago

0.3.18

10 months ago

0.3.9

10 months ago

0.3.17

10 months ago

0.3.16

10 months ago

0.3.15

10 months ago

0.3.14

10 months ago

0.3.13

10 months ago

0.3.12

10 months ago

0.3.11

10 months ago

0.3.10

10 months ago

0.1.52

1 year ago

0.1.53

1 year ago

0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.14

1 year ago

0.1.15

1 year ago

0.1.50

1 year ago

0.1.51

1 year ago

0.1.49

1 year ago

0.1.41

1 year ago

0.1.42

1 year ago

0.1.43

1 year ago

0.1.44

1 year ago

0.1.45

1 year ago

0.1.46

1 year ago

0.1.47

1 year ago

0.1.48

1 year ago

0.2.10

10 months ago

0.1.40

1 year ago

0.1.38

1 year ago

0.1.8

1 year ago

0.1.39

1 year ago

0.1.7

1 year ago

0.1.9

1 year ago

0.1.4

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.30

1 year ago

0.1.31

1 year ago

0.1.32

1 year ago

0.1.33

1 year ago

0.1.34

1 year ago

0.1.35

1 year ago

0.1.36

1 year ago

0.1.37

1 year ago

0.1.27

1 year ago

0.1.28

1 year ago

0.1.29

1 year ago

0.1.20

1 year ago

0.1.21

1 year ago

0.1.22

1 year ago

0.1.23

1 year ago

0.1.24

1 year ago

0.1.25

1 year ago

0.1.26

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.7

10 months ago

0.1.16

1 year ago

0.2.6

10 months ago

0.1.17

1 year ago

0.2.9

10 months ago

0.1.18

1 year ago

0.2.8

10 months ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago