Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

open-hotel/kalango-orm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kalango

Kalango is an ORM for ArangoDB that utilizes TypeScript language features to make modeling your database easier.

Installation

# With NPM
$ npm install --save kalango

# With Yarn
$ yarn add kalango

Create a new database connection

// index.ts
import { createConnection } from 'kalango';

createConnection({
  url: 'arangodb://localhost:8529',
  user: 'root',
  password: 'root',
  database: 'root',
  syncronize: true, // Disable in production
}).then((db) => {
  // db is ready!
})

Define entities

Entities are a way of representing your collections.

// user.entity.ts
import { Entity, Attribute } from 'kalango';

@Entity()
export class User {
  @Attribute()
  name: string

  @Attribute()
  email: string
}

Register entities

Entities must be added to the connection before they can be used.

// index.ts
import { createConnection } from 'kalango';
import { User } from './user.entity.ts'; // Import here

createConnection({
  url: 'arangodb://localhost:8529',
  user: 'root',
  password: 'root',
  database: 'mydb',
  syncronize: true,
  entities: [User], // Add this,
  // entities: ['./**/*.entity.js'], // Or add this to import all files with the extension .entity.ts
}).then((db) => {
  // db is ready!
})

Repositories

Repositories are used to manage the data of an entity.

// index.ts
import { createConnection } from 'kalango';
import { User } from './user.entity.ts'; // Import here

createConnection({
  url: 'arangodb://localhost:8529',
  user: 'root',
  password: 'root',
  database: 'mydb',
  syncronize: true,
  entities: [User],
}).then((db) => {
  const UserRepository = db.repositoryFor('User')

  // Create a new user
  const john = await UserRepository.save({
    name: 'John',
    email: '[email protected]'
  })

  john.email = '[email protected]'

  // Updates a user
  await UserRepository.save(john)

  // List users
  const users = await UserRepository.findAll()

  // Delete a user
  await UserRepository.delete(john)
})

Releases

No releases published

Packages

No packages published