Data Types

Bedrock provides various data types to use with your agent-specific data

Bedrock is a distributed database, and the key word there is data. We provide several "common" types that we think will be useful, but we're not omniscient, so we allow users to specify (pretty much) any type they desire. They do this by using a uniquely-named data type and using the %general columns type and specifying a schema. The schema is just an ordered list of [name, type] of the columns in their custom %general type. In addition to all typical atom code, we support string maps, sets, lists, and paths and our own id type which is useful for defining dependent relationships (a hallmark of any relational database)

+$  row
  $:  =path             :: application-specific logic about what this row is attached to (ie /space/space-path/app/app-name/thing)
                        :: is used to push data out to peers list for that path
      =id:common
      =type:common      :: MUST always be same as table type
      v=@ud             :: data-type version
      data=columns      :: the actual content
      created-at=@da    :: when the source-ship originally created the row
      updated-at=@da    :: when the source-ship originally last updated the row
      received-at=@da   :: when this ship actually got the latest version of the row, regardless of when the row was originally created
  ==
+$  columns
  $%  [%general cols=(list @)]
      [%vote vote:common]
      [%rating rating:common]
      [%comment comment:common]
      [%tag tag:common]
      [%link link:common]
      [%follow follow:common]
      [%relay relay:common]
      [%react react:common]
  ==
+$  schemas   (map [=type:common v=@ud] schema)
+$  schema    (list [name=@t t=@t])  :: list of [column-name type-code]
:: allowable @t codes are:
::  @t @ud etc (any atom code)
::  id    (for a id:common type of [=ship t=@da], useful for referencing other rows from within your custom-type
::  unit  (for a (unit @t) only)
::  path
::  list  (for a list of @t)
::  set   (for a set of @t)
::  map   (for a map of @t to @t)

Common Types

We've defined several common data types that could be used in various applications.

%vote

  • likes / dislikes

  • upvotes / downvotes

:: like/dislike upvote/downvote
+$  vote
  $:  up=?              :: true for like/upvote, false for dislike/downvote  0 -> 2
      parent-type=type  :: table name of the thing this vote is attached to  1 -> 6
      parent-id=id      :: id of the thing this vote is attached to          2 -> 14
      parent-path=path  ::                                                   3 -> 30
  ==

%rating

5 star rating, 100% scoring, etc.

+$  rating
  $:  value=@rd         :: the rating. any real number. up to app to parse properly
      max=@rd           :: the maximum rating the application allows. (useful for aggregating, and making display agnostic)
      format=@tas       :: an app-specific code for indicating what "kind" of rating it is (5-star or 100% or 7/10 cats or whatever)
      parent-type=type  :: table name of the thing being rated
      parent-id=id      :: id of the thing being rated
      parent-path=path
  ==

%comment

Plain text snippet referencing some other object

+$  comment
  $:  txt=@t            :: the comment
      parent-type=type  :: table name of the thing being commented on
      parent-id=id      :: id of the thing being commented on
      parent-path=path
  ==

%tag

Tag some data with metadata (ex: 'schizo' 'memes' 'programming' etc)

+$  tag
  $:  tag=@t            :: the tag (ex: 'based')
      parent-type=type  :: table name of the thing being tagged
      parent-id=id      :: id of the thing being tagged
      parent-path=path
  ==

%follow

Follow updates on a specific path for a specific ship.

+$  follow
  $:  leader=ship
      follower=ship     
      domain=path   :: maybe I only want to follow ~zod's %recipes, not their %rumors posts
  ==

%relay

The relay table is necessary for making "retweets" work on Urbit. The goal includes the ability to count retweets within a space should come with ability to relay to all paths or just to a particular path.

Relay protocols

  • %static: relays once and doesn't sync changes from the source data

  • %edit: relays will push new changes when source data is updated

  • %all: relays will push new changes and also delete when/if the original is deleted

+$  relay-protocol  ?(%static %edit %all)
+$  relay
  $:  =id   :: the id of what is being relayed
      =type :: type of what is being relayed
      =path :: where the thing originally came from
      revision=@ud
      protocol=relay-protocol
      deleted=?
  ==
--

%react

This type defined reactions (emoji) that are used in place like chat reactions in Courier.

+$  react
  $:  react=@t          :: the emoji code
      parent-type=type  :: table name of the thing being commented on
      parent-id=id      :: id of the thing being commented on
      parent-path=path
  ==

Last updated