dgraph简单介绍
1. 概述
dgraph 是基于 golang 开发的开源的分布式图数据库.
2. 基本概念
与其他数据库不同,图库中的数据采用一下方式进行描述:
[subject]->[predicate]->[object]
[主体]->[谓语]->[实体]
<0x01> <name> 'Alice'
<0x01> <age> 13
2. Schema
dgraph使用schema描述谓词(predicate).
2.1 默认类型
类型 | go | 举例 | 说明 |
---|---|---|---|
default | string | Alice |
|
int | int64 | 13 |
|
float | float | 13.5 |
|
string | string | Alice |
|
bool | bool | true |
|
dateTime | time.Time | 2006-01-02T15:04:05.999999999 |
RFC3339 |
geo | go-geom | 参照go-geom | |
password | string | 加密之后字符串,无法返回,只能判断 | |
uid | uint64 | 0x1 |
数据库子增ID |
[] |
[] |
[uid] | 数组 |
2.2 定义谓词(predicate)
使用一下方式定义谓词:<predicate>: <type> @<attr1>(<tokenizer>) @<attr2> .
<predicate>
: 是要定义的谓词<type>
: 谓词的类型@<attr1>(<tokenizer>)
: 谓词的属性.
: 结束符
示例:
name: string @index(exact, fulltext) @count .
age: int @index(int) .
friend: uid @count .
dob: dateTime .
location: geo @index(geo) .
occupations: [string] @index(term) .
2.3 自定义类型
可以将定义好的谓词,自由组合成新的类型。
type User {
name
age
friend
dob
location
occupations
}
注意:需要在插入数据时,特别插入数据的类型
{
"name": "Alice",
"age": 13,
"friend": {
"uid": "0x1345"
},
"dgraph.type": "User"
}
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 wind.kaisa@gmail.com