store

module
v0.0.0-...-153d94f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2018 License: GPL-3.0

README

Build Status codecov

TopicRelation

TopicRelationStore is a type of general purpose store for 'topics' and 'relations' between. At the basis the SQL version comprises a 'topic table' and a 'relation table'. Relation table is a way to address simple linking between topics (directed graph). See table model below. The model is somewhat similar to link benchs model. Be aware that this is not as performant as some graph database models.

Usage: Group

Group model and the related GroupStore can be used to store and retrieve topics which do have some sort of "members" effectively. BaseGroup and BaseGroupMember types are defined in the proto file and can be extended easily.

Check github.com/kapitan-k/store/topicrelation/example

  // our group
  // id will be generated by groupStore
  g := group.BaseGroup{}
  g.Name = "MY GROUP"
  g.CreatedTime = createdTime

  // the members
  // their status can be defined by visibility
  gm1 := group.BaseGroupMember{}
  gm1.ID = 101
  gm1.Name = "Lara"
  gm1.Visibility = 1

  gm2 := group.BaseGroupMember{}
  gm2.ID = 102
  gm2.Name = "Arthur"
  gm2.Visibility = 1

  g.GroupMembers = []group.BaseGroupMember{
    gm1,
    gm2,
  }

  // insert the group g
  err = groupStore.InsertGroup(&g)
  PanicOnError(err)

  h := group.NewBaseGroupUnmarshalHandle()
  err = groupStore.GetGroupsByIDIN(true, h, g.ID)
  PanicOnError(err)

Extend the whole thingy by a custom marshaler method and unmarshaler handle.

SQLTables

An example topic table in SQL could look like this:

  CREATE TABLE topic(
  id bigint(20) unsigned NOT NULL DEFAULT '0',
  topic_type bigint(20) unsigned NOT NULL DEFAULT '0',
  owner_id bigint(20) unsigned NOT NULL DEFAULT '0',
  name varchar(255) NOT NULL DEFAULT '0',
  created_time bigint(20) unsigned NOT NULL DEFAULT '0',
  updated_time bigint(20) unsigned NOT NULL DEFAULT '0',
  version bigint(20) unsigned NOT NULL DEFAULT '0',
  visibility bigint(20) unsigned NOT NULL DEFAULT '0',
  data longblob,
  PRIMARY KEY (id) COMMENT 'cf_topic_pk',
  UNIQUE KEY (name) COMMENT 'cf_topic_name',
  KEY (owner_id, id) COMMENT 'cf_topic_owner_id',
  KEY (topic_type, id) COMMENT 'cf_topic_type_id'
) ENGINE=RocksDB DEFAULT COLLATE=latin1_bin;

An example relation table in SQL could look like this:

  CREATE TABLE relation(
  id bigint(20) unsigned NOT NULL DEFAULT '0',
  topic_type bigint(20) unsigned NOT NULL DEFAULT '0',
  owner_id bigint(20) unsigned NOT NULL DEFAULT '0',
  name varchar(255) NOT NULL DEFAULT '0',
  created_time bigint(20) unsigned NOT NULL DEFAULT '0',
  updated_time bigint(20) unsigned NOT NULL DEFAULT '0',
  version bigint(20) unsigned NOT NULL DEFAULT '0',
  visibility bigint(20) unsigned NOT NULL DEFAULT '0',
  data longblob,
  PRIMARY KEY (topic_type, id, owner_id) COMMENT 'cf_relation_pk',
  KEY (id, owner_id, topic_type) COMMENT 'cf_relation_back',
  KEY (owner_id, topic_type, visibility, updated_time, id, version) COMMENT 'rev:cf_relation_owner_id_type',
  KEY (name) COMMENT 'cf_name'
) ENGINE=RocksDB DEFAULT COLLATE=latin1_bin;

The data column could also be used with JSON type which gives you more querying capabilities.

Directories

Path Synopsis
engines
sql
Package topicrelation is a generated protocol buffer package.
Package topicrelation is a generated protocol buffer package.
group
Package gp is a generated protocol buffer package.
Package gp is a generated protocol buffer package.
sql

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL