Simplified schema creation, queries and mutations for Dgraph.
npm install dgraph-orm
Depending on the version of Dgraph that you are connecting to, you will have to use a different version.
Dgraph version | dgraph-orm version |
---|---|
1.0.X | 1.X.Y |
1.1.X | 2.X.Y |
Note: Only API breakage from v1.X.Y to v2.X.Y is in dependency -dgraph-js
.
Function DgraphClient.newTxn().mutate()
returns a messages.Assigned
type in v1.X but a messages.Response
type in v2.X.
https://avishwakarma.github.io/dgraph-orm
import dgraph from 'dgraph-orm';
const UserSchema = new dgraph.Schema('user', {
name: {
type: dgraph.Types.STRING,
index: true,
token: {
term: true
}
},
email: {
type: dgraph.Types.STRING,
index: true,
unique: true,
token: {
exact: true
}
},
password: dgraph.Types.PASSWORD,
bio: dgraph.Types.STRING,
friend: {
type: dgraph.Types.UID,
model: 'user', // related model name
count: true,
reverse: true
}
});
/**
* Set and create model out of the schema
*/
const User = dgraph.model(UserSchema);
/**
* Creates a new user with passed fields
*
* Returns the created user along with the generated uid
*/
const user = await User.create({
name: 'Ashok Vishwakarma',
email: 'akvlko@gmail.com',
bio: 'My bio ...'
});
console.log(user);
// {
// uid: '0x1',
// name: 'Ashok Vishwakarma',
// email: 'akvlko@gmail.com',
// bio: 'My bio ...'
// }
For the full documentation please visit the below link
https://ashokvishwakarma.github.io/dgraph-orm
- Other geo queries within, intersects
- Group by
- Aggregation
Issues and pull requests are welcome for
- Unit test cases
- Feature and query method implementation
- Bug fixes