Coder Social home page Coder Social logo

abstractions's Introduction

Enjoy working with Dune? We're hiring developers remotely!

Abstractions

This repository tracks user-created abstractions to the Dune Analytics data platform. Contributions in the form of issues and pull requests are very much welcome here.

Guidelines and conventions

  • Folders within the {ethereum/, xdai/} folder maps to schema names (project names) in the relevant Dune dataset. Make sure to get the right schema.
  • Each file should only contain one table, view, materialized view or function declaration.
  • Files should have names matching their declared object. I.e. if a file declares CREATE VIEW x.view_y, the file should be ethereum/x/view_y.sql
  • Each file should be run in a transaction. I.e. either have one statement or be wrapped in BEGIN; and COMMIT;

Objects

Views

View names should be prefixed by view_. If the view is defined as CREATE VIEW view_ctokens AS, then the file should be called view_ctokens.sql.

Materialized Views

Materialized view names should be prefxied by view_, same as normal views. Additionally, a materialized view must specify at what interval it should be refreshed. This is done by adding the following block to the end of the declaration:

INSERT INTO cron.job(schedule, command)
VALUES ('* 1 * * *', $$REFRESH MATERIALIZED VIEW CONCURRENTLY x.view_y$$)
ON CONFLICT (command) DO UPDATE SET schedule=EXCLUDED.schedule;

Note that the preferred way to refresh a materialized view is using the CONCURRENTLY keyword, and that this mandates the existence of a UNIQUE index on the materialized view. See more info here.

Tables

Tables are declared without any prefix in the name. If the table x.y needs to be periodically updated, the convention is to create a companion function x.insert_y(from timestamptz, to timestamptz=now()). It is then customary to do

INSERT INTO cron.job (schedule, command)
VALUES ('* 1 * * *', $$SELECT x.insert_y((SELECT max(block_time) - interval '1 days' FROM x.y));$$)
ON CONFLICT (command) DO UPDATE SET schedule=EXCLUDED.schedule;

Functions

Functions that are not companion functions to tables, should be prefixed by fn_.

Other conventions

  • Objects (tables, views, materialized views, functions) should be names in lowercase_snake_cased
  • Columns should be lowercase_snake_cased
  • Use block_time to indicate the time of an event, not timestamp, ts, evt_block_time

abstractions's People

Contributors

mewwts avatar msilb7 avatar bh2smith avatar milkyklim avatar hagaetc avatar masquot avatar k06a avatar markusbkoch avatar mendesfabio avatar 0xroll avatar 0xboxer avatar va3093 avatar schoeler avatar anxolin avatar antonio-mendes avatar josephd8 avatar 0xtekgrinder avatar aalan3 avatar sui414 avatar echolon166 avatar primalglenn avatar evan-kim2028 avatar ivigamberdiev avatar gosuto-inzasheru avatar howardpen9 avatar dsalv avatar chrispearcx avatar kevinxzhang avatar yulesa avatar defienjoyer avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.