0.10.6 • Published 6 days ago

@blitznocode/blitz-orm v0.10.6

Weekly downloads
-
License
AGPL-3.0-only
Repository
github
Last release
6 days ago

Blitz-orm

Blitz-orm is an Object Relational Mapper (ORM) for graph databases that uses a JSON query language called Blitz Query Language (BQL). BQL is similar to GraphQL but uses JSON instead of strings. This makes it easier to build dynamic queries.

Blitz-orm is similar to other ORM packages such as Prisma. You define a BQL schema and it gets translated to different databases (currently only compatible with TypeDB but a dgraph adapter in the oven).

Compatibility

Currently, the only database that is compatible with Blitz-orm is TypeDB. The goal is to build adapters for other graph databases such as Dgraph and Neo4j, as well as classic databases like PostgreSQL and MongoDB in the future.

How to Use

  1. Install the package using your package manager, for example: yarn add @blitznocode/blitz-orm
  2. Create a Borm schema. You can find an example in the test folder.
  3. The borm.define() function is currently not working, so you will need to manually translate your BQL schema into a TypeQL schema (an example can be found in the test folder).
  4. Create a configuration file with the database name that you have created in TypeDB.
  5. Initialize Blitz-orm in a file like this:
import BormClient from '@blitznocode/blitz-orm';

import { bormConfig } from './borm.config';
import { schema } from './schema';

const bormClient = new BormClient({
  schema,
  config: bormConfig,
});

export default bormClient;
  1. You can then run queries and mutations like this:
const res = await bormClient.mutate({$entity: 'User', name: 'Ann'}, { noMetadata: true });

Gotchas

1) There is no borm.define() method yet. This means you will need to translate your borm schema into typeQL schema manually 2) Private (non shared) attributes are defined in typeDB as "nameOfTheThing·nameOfTheAttribute", where "·" is a mid-do. As an example:

#shared attribute (shared: true) :
title sub attribute, value string;
#as a private attribute (shared: false), default behaviour:
book·title sub attribute, value string;

Documentation & example queries

You can find example mutations and queries in the tests There is no official documentation but you can check the draft RFC: https://www.notion.so/blitzapps/BlitzORM-RFC-eb4a5e1464754cd7857734eabdeaa73c

The RFC includes future features and is not updated so please keep an eye on the query and mutation tests as those are designed for the features already working.

How to Run TypeDB Locally

To run TypeDB locally, follow the official instructions at https://docs.vaticle.com/docs/running-typedb/install-and-run. It is recommended to run TypeDB Studio, define the schema there, and test with pure TypeQL before using Blitz-orm.

Collaboration & Contact

You can contribute to the project by adding adapters for other databases, developing a BQL-to-GraphQL mapper, enhancing performance, or contributing to the public roadmap for this package (not yet published). To get in touch, please send an email to loic@blitznocode.com.

Warning

Blitz-orm is currently in alpha version and not ready for production use. Some key queries and mutations do work, but there is still much that needs to be done and performance improvements are needed. One of the biggest performance issues is with nested queries, as they currently require a call to TypeDB for each level of depth.

What is Currently Working

To see what is currently working and find examples, please check the test folder, where you will find a variety of queries and mutations.

TypeGen

This orm includes a basic typeGen that gets you types depending on the structure of the borm Schema. You can use it like this:

type UserType = GenerateType<typeof typesSchema.relations.User>;

Due to typescript limitations and also to be able to type fields from extended things, you will need to compile your bormSchema to a particular format. In order to make this work you can see the example that we have in the tests that you can run with pnpm test:buildSchema.

You can also use it with your base schema without compiling but some fields might not be there and you might need to ignore some ts errors. Also you will need "as const" at the end of your schema.

The future of this package

  • Achieve 100% compatibility with typeDB functions
  • Enhance functionality with new features such as, cardinality management, ordered attributes, Vectors (ordered relations)...
  • Expand compatibility to other graph databases and traditional databases such as PostgreSQL or MongoDB
  • Enable the ability to split queries and mutations across multiple databases (for example, some data stored in PostgreSQL and other data in typeQL, all queried from a single point)

Development

  • We use pnpm as a package manager
  • You will need to add "-w", for instance pnpm add -D husky -w
0.10.6

6 days ago

0.10.5

8 days ago

0.10.4

21 days ago

0.10.0

1 month ago

0.9.19

2 months ago

0.9.17

2 months ago

0.9.18

2 months ago

0.9.12

3 months ago

0.9.13

3 months ago

0.9.14

3 months ago

0.9.15

3 months ago

0.9.10

3 months ago

0.9.11

3 months ago

0.9.0

3 months ago

0.9.2

3 months ago

0.9.1

3 months ago

0.9.8

3 months ago

0.9.7

3 months ago

0.9.9

3 months ago

0.9.4

3 months ago

0.9.3

3 months ago

0.9.6

3 months ago

0.9.5

3 months ago

0.8.11

3 months ago

0.8.10

3 months ago

0.8.9

3 months ago

0.8.7

3 months ago

0.8.4

3 months ago

0.8.6

3 months ago

0.8.3

3 months ago

0.8.2

3 months ago

0.8.0

4 months ago

0.7.4

4 months ago

0.7.3

4 months ago

0.7.2

4 months ago

0.7.1

4 months ago

0.7.0-beta

4 months ago

0.1.10

10 months ago

0.1.11

10 months ago

0.1.12

10 months ago

0.4.8

7 months ago

0.3.0

7 months ago

0.2.1

9 months ago

0.2.0

10 months ago

0.6.3

6 months ago

0.4.5

7 months ago

0.2.7

7 months ago

0.1.8

10 months ago

0.6.2

7 months ago

0.5.3

7 months ago

0.4.4

7 months ago

0.1.7

10 months ago

0.4.7

7 months ago

0.6.4

6 months ago

0.4.6

7 months ago

0.5.0

7 months ago

0.4.1

7 months ago

0.3.2

7 months ago

0.4.0

7 months ago

0.3.1

7 months ago

0.2.2

8 months ago

0.6.1

7 months ago

0.5.2

7 months ago

0.4.3

7 months ago

0.2.5

8 months ago

0.1.6

11 months ago

0.6.0

7 months ago

0.5.1

7 months ago

0.4.2

7 months ago

0.3.3

7 months ago

0.1.5

11 months ago

0.1.4

11 months ago

0.1.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.42

1 year ago

0.0.43

1 year ago

0.0.44

1 year ago

0.0.45

1 year ago

0.0.46

1 year ago

0.0.41

1 year ago

0.0.40

1 year ago

0.0.39

1 year ago