Skip to content

adam-cowley/neode-ogm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NeodeGM

Experiments in how neode could become more object oriented.

Example

  • Create your model as a class:

// Create
@Node({ labels: ['Person', 'Actor'] })
export default class Person {
    @Uuid()
    @Primary()
    @Unique()
    id: string;

    @String()
    name: string;

    getId() {
        return this.id
    }

    getName() {
        return this.name
    }
}
  • Write some code:

// Connect from .env
const neode = neode.fromEnv()

// TOOD: Open a transaction
neode.openTransaction()

// Create an object
const adam = new Person("92702e6b-4d39-4ad2-a4ad-cc3923496090", 'Adam')

// Save it
neode.save(adam)

// Retrieve it
const found = neode.find(Person, "92702e6b-4d39-4ad2-a4ad-cc3923496090")

Repository Pattern

  • Create a repository based on the model:

// Use decorator to register the PersonRepository as using the Person node
@RepositoryDecorator(Person)
export default class PersonRepository extends Repository<Person> {}
  • Create an instance of the repository and use it

[source,typescript]w

const repo = new PersonRepository()
const adam = repo.find("92702e6b-4d39-4ad2-a4ad-cc3923496090")

Transaction Management (TODO)

  • Call the main repo to open a transaction - this will return a transaction based instance of neode. The save, create, (etc) methods will run everything in the context of a single transaction.

  • Otherwise the base class will create a new transaction every time.

neode.inWriteTransaction()
    .then(async inTx => {
        const adam = new Person("92702e6b-4d39-4ad2-a4ad-cc3923496090", 'Adam')
        await inTx.save(adam)

        const arthur = new Person("92702e6b-4d39-4ad2-a4ad-cc3923496090", 'Arthur')
        await inTx.save(arthur)

        await inTx.commit()
    })

Annotations (TODO)

  • @NeodeRepository

Entities

  • @NodeEntity

  • @RelationshipEntity

Property Types

  • ✓ @String

  • ✓ @Uuid

  • ❏ @Int

  • ❏ @Float

  • ❏ @Number

  • ❏ @Property

Relationships

  • ❏ @OneToOne

  • ❏ @OneToMany

Writing

  • ❏ @Default

  • ❏ @OnCreateSet

  • ❏ @OnMatchSet

Schema

  • ❏ @Primary

  • ❏ @Unique

Other TODO’s

  • neode.installSchema()

About

Neode OGM Experiments

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published