db

package module
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: Apache-2.0 Imports: 1 Imported by: 4

README

codex-db

Codex-db provides the database packages needed for the codex project.

Build Status Dependency Updateer codecov.io Go Report Card Quality Gate Status Apache V2 License GitHub Release GoDoc

Summary

Codex-db provides the database packages needed for the codex project.

Table of Contents

Code of Conduct

This project and everyone participating in it are governed by the XMiDT Code Of Conduct. By participating, you agree to this Code.

Install

This repo is a library of packages. There is no installation.

Cassandra DB Setup

CREATE KEYSPACE IF NOT EXISTS devices;
CREATE TABLE devices.events (device_id  varchar,
    record_type INT,
    birthdate BIGINT,
    deathdate BIGINT,
    data BLOB,
    nonce BLOB,
    alg VARCHAR,
    kid VARCHAR,
    row_id TIMEUUID,
    PRIMARY KEY (device_id, birthdate, record_type))
    WITH CLUSTERING ORDER BY (birthdate DESC, record_type ASC)
    AND default_time_to_live = 2768400
    AND transactions = {'enabled': 'false'};
CREATE INDEX search_by_record_type ON devices.events
    (device_id, record_type, birthdate) 
    WITH CLUSTERING ORDER BY (record_type ASC, birthdate DESC)
    AND default_time_to_live = 2768400
    AND transactions = {'enabled': 'false', 'consistency_level':'user_enforced'};
CREATE INDEX search_by_row_id ON devices.events
    (device_id, row_id) 
    WITH CLUSTERING ORDER BY (row_id DESC)
    AND default_time_to_live = 2768400
    AND transactions = {'enabled': 'false', 'consistency_level':'user_enforced'};
CREATE TABLE devices.blacklist (device_id varchar PRIMARY KEY, reason varchar);

Contributing

Refer to CONTRIBUTING.md.

Documentation

Overview

package db provides some overarching variables, structs, and interfaces that different database implementations can use and implement and consumers can expect.

Index

Constants

View Source
const (
	// TypeLabel is for labeling metrics; if there is a single metric for
	// successful queries, the typeLabel and corresponding type can be used
	// when incrementing the metric.
	TypeLabel         = "type"
	InsertType        = "insert"
	DeleteType        = "delete"
	ReadType          = "read"
	PingType          = "ping"
	BlacklistReadType = "blacklistRead"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EventType

type EventType int

EventType is an enum for specifying the type of event being stored.

const (
	// default event type
	Default EventType = iota

	// event type for online and offline events
	State
)

func ParseEventType

func ParseEventType(event string) EventType

ParseEventType returns the enum when given a string.

func (EventType) String

func (i EventType) String() string

type Inserter

type Inserter interface {
	InsertRecords(records ...Record) error
}

Inserter is something that can insert records into the database.

type Pruner

type Pruner interface {
	GetRecordsToDelete(shard int, limit int, deathDate int64) ([]RecordToDelete, error)
	// PruneRecords(records []int) error
	DeleteRecord(shard int, deathdate int64, recordID int64) error
}

Pruner is something that can get a list of expired records and delete them. Deleting is done individually.

type Record

type Record struct {
	Type      EventType `json:"recordtype" bson:"recordtype" gorm:"recordtype:int"`
	DeviceID  string    `json:"deviceid" bson:"deviceid"`
	BirthDate int64     `json:"birthdate" bson:"birthdate"`
	DeathDate int64     `json:"deathdate" bson:"deathdate"`
	Data      []byte    `json:"data" bson:"data"`
	Nonce     []byte    `json:"nonce" bson:"nonce"`
	Alg       string    `json:"alg" bson:"alg"`
	KID       string    `json:"kid" bson:"kid" gorm:"Column:kid"`
	RowID     string    `json:"rowid"`
}

Record is the struct used to insert an event into the database. It includes the marshaled, and possibly encrypted, event ("Data") and then other metadata to be used for the record. If the data is encrypted, the Nonce, Alg, and KID values will be needed to determine how to correctly decrypt it.

func (Record) TableName

func (Record) TableName() string

TableName sets Record's table name to be "events"; for the GORM driver.

type RecordGetter

type RecordGetter interface {
	GetRecords(deviceID string, limit int, stateHash string) ([]Record, error)
	GetRecordsOfType(deviceID string, limit int, eventType EventType, stateHash string) ([]Record, error)
	GetStateHash(records []Record) (string, error)
}

RecordGetter is something that can get records, including only getting records of a certain type.

type RecordToDelete

type RecordToDelete struct {
	DeathDate int64 `json:"deathdate" bson:"deathdate"`
	RecordID  int64 `json:"recordid" bson:"recordid"`
}

RecordToDelete is the information needed to get out of the database in order to call the DeleteRecord function

Directories

Path Synopsis
package batchDeleter provides a wrapper around the db.Pruner to provide a way to get expired records at a given interval and delete them at a separate given interval.
package batchDeleter provides a wrapper around the db.Pruner to provide a way to get expired records at a given interval and delete them at a separate given interval.
package batchInserter provides a wrapper around the db.Inserter to provide a way to group records together before inserting, in order to decrease database requests needed for inserting.
package batchInserter provides a wrapper around the db.Inserter to provide a way to group records together before inserting, in order to decrease database requests needed for inserting.
package cassandra provides a way to connect to a cassandra database to keep track of device events.
package cassandra provides a way to connect to a cassandra database to keep track of device events.
package postgresql provides a way to connect to a postgresql database to keep track of device events.
package postgresql provides a way to connect to a postgresql database to keep track of device events.
Package dbretry contains structs that implement various db interfaces as well as consume them.
Package dbretry contains structs that implement various db interfaces as well as consume them.

Jump to

Keyboard shortcuts

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