kaisawind's blog
  • 关于
  • 所有帖子

dgraph简单介绍 - Fri, Aug 7, 2020

dgraph简单介绍

1. 概述

dgraph 是基于 golang 开发的开源的分布式图数据库.

2. 基本概念

与其他数据库不同,图库中的数据采用一下方式进行描述:

[subject]->[predicate]->[object]

[主体]->[谓语]->[实体]

<0x01> <name> 'Alice' <0x01> <age> 13

2. Schema

dgraph使用schema描述谓词(predicate).

2.1 默认类型

类型go举例说明
defaultstringAlice
intint6413
floatfloat13.5
stringstringAlice
boolbooltrue
dateTimetime.Time2006-01-02T15:04:05.999999999RFC3339
geogo-geom参照go-geom
passwordstring加密之后字符串,无法返回,只能判断
uiduint640x1数据库子增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"
}


辽ICP备2021007608号 | © 2025 | kaisawind

Facebook Twitter GitHub