Skip to content

Commit 6ff5760

Browse files
Merge pull request #24 from xanthous-tech/develop
Develop
2 parents ebd8bda + d97cc05 commit 6ff5760

109 files changed

Lines changed: 21879 additions & 20095 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
rules: {
1313
'no-inner-declarations': 'off',
1414
'prefer-spread': 'off',
15+
'@typescript-eslint/camelcase': 'warn',
1516
'@typescript-eslint/no-namespace': 'off',
1617
'@typescript-eslint/no-use-before-define': 'off',
1718
'@typescript-eslint/no-non-null-assertion': 'off',

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
docs
3+
4+
node_modules

README.md

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,100 @@
1-
# dgraph-orm
2-
dGraph ORM written in TypeScript
1+
# DGraph ORM
2+
3+
A decorator based object mapper, schema handler, mutation tracker to use with dgraph.
4+
5+
This library handles objects and their relation and generates mutation/deletion strings based on
6+
changes. These strings can be used with any dgraph client to mutate the data.
7+
8+
# Getting started
9+
10+
```
11+
yarn add @xanthous/dgraph-orm
12+
```
13+
14+
Here is an example to create a new graph using some of the public APIs exposed by the ORM.
15+
16+
```typescript
17+
import {
18+
Uid,
19+
Node,
20+
Property,
21+
Predicate,
22+
IPredicate,
23+
QueryBuilder,
24+
SchemaBuilder,
25+
TransactionBuilder
26+
} from '@xanthous/dgraph-orm';
27+
28+
/**
29+
* A Node definition of person
30+
*/
31+
@Node()
32+
class Person {
33+
@Uid()
34+
id: string;
35+
36+
@Property()
37+
name: string;
38+
39+
@Predicate({ type: () => Person })
40+
friends: IPredicate<Person>;
41+
}
42+
43+
// Schema generated based on the node definitions.
44+
const schema = SchemaBuilder.build();
45+
console.log(schema);
46+
// type Person {
47+
// Person.name: string
48+
// Person.friends: [Person]
49+
// }
50+
// Person.name: string .
51+
// Person.friends: [uid] @count .
52+
53+
// Query builder can be used to easily create query fragments based on the definitions.
54+
const { handle, fragment } = QueryBuilder.buildFragment(Person);
55+
console.log(handle);
56+
// ...personDataFragment
57+
58+
console.log(fragment);
59+
// fragment personDataFragment {
60+
// Person.name
61+
// Person.friends
62+
// id
63+
// }
64+
65+
// Create a transaction
66+
const transaction = TransactionBuilder.build();
67+
68+
// Create some people
69+
const john = transaction.nodeFor(Person);
70+
const jane = transaction.nodeFor(Person);
71+
const kamil = transaction.nodeFor(Person);
72+
73+
// A temporary uid is assigned during object creation.
74+
console.log(john.id);
75+
// b830c1f5ca09d466 ## random
76+
77+
// Change their names
78+
john.name = 'John';
79+
jane.name = 'Jane';
80+
kamil.name = 'Kamil';
81+
82+
// Create connections between them
83+
kamil.friends.add(jane);
84+
kamil.friends.add(john);
85+
86+
// Create a mutation string to use with dgraph js client.
87+
const mutation = transaction.getSetNQuadsString();
88+
console.log(mutation);
89+
// _:b830c1f5c787c210 <dgraph.type> "Person" .
90+
// _:b830c1f5c787c210 <Person.name> "John"^^<xs:string> .
91+
// _:b830c1f5c78a5947 <dgraph.type> "Person" .
92+
// _:b830c1f5c78a5947 <Person.name> "Jane"^^<xs:string> .
93+
// _:b830c1f5c78afce1 <dgraph.type> "Person" .
94+
// _:b830c1f5c78afce1 <Person.name> "Kamil"^^<xs:string> .
95+
// _:b830c1f5c78afce1 <Person.friends> _:b830c1f5c78a5947 .
96+
// _:b830c1f5c78afce1 <Person.friends> _:b830c1f5c787c210 .
97+
```
398

499
# Sponsors
5100

0 commit comments

Comments
 (0)