48

Crux Earth Assignment: Getting Started

 5 years ago
source link: https://www.tuicool.com/articles/qqYn6vn
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

IZraiiY.png!web FnYNbeN.png!web 73ma2qm.png!web VFfYZfJ.png!web j6VN3aj.png!web FJJFFfJ.png!web VfyUJfM.png!web

Introduction

Welcome to the official Crux tutorial, which complements the officialdocumentation.

If you’re new to Crux and want to get a practical hands-on guide, you’re in the right place.

The Story

It’s the year 2115. You have been hired by an inter-planetary bank, Helios Banking Inc. Your task is to travel around the solar system completing assignments using Crux.

You have been given a company spaceship so transport won’t be a problem. Space Customs require all astronauts to complete a flight manifest for every journey. You also have a handy Crux manual with you so you can read up on some background information before you get stuck into each assignment.

Let’s begin.

Setup

You need to get Crux running before you can use it.

Choose your path:

You are not familiar with Clojure You are familiar with Clojure

Follow the Nextjournal edition of this tutorial.

Continue to either using Crux in theor in your.

yemiyuf.jpg!web

In the REPL

You use Leiningen to set up a new app. There is an entry for this in your Crux manual:

Crux can be included as a dependency in your project.clj as:

(defproject crux-tutorial "0.1.0-SNAPSHOT"
    :dependencies [[org.clojure/clojure "1.10.0"]
                   [juxt/crux-core "RELEASE"]])

— Crux manual

Read More

You start the REPL with the command lein repl and require Crux:

(require '[crux.api :as crux])

You are now ready for your first assignment, so you head over to the.

In your project

Update your deps.edn with Crux as a dependency and create a namespace for Crux.

{:deps
   {org.clojure/clojure {:mvn/version "1.10.0"}
    org.clojure/tools.deps.alpha
    {:git/url "https://github.com/clojure/tools.deps.alpha.git"
     :sha "f6c080bd0049211021ea59e516d1785b08302515"}
    juxt/crux-core {:mvn/version "RELEASE"}}}
(ns crux-tutorial
    (:require [crux.api :as crux]))

Space Port

On entering your spaceship, you notice a flashing blue light on the left of your communications panel. You submit an iris scan to unlock your first message.

A warm welcome from the Helios family.

For your first assignment we would like you to go to Pluto and help Tombaugh Resources Ltd. set up their stock reporting system. There will be a ticket with more information waiting for you upon your arrival. Find Reginald if you have any questions.

Safe journeys, and don’t forget to fill in your flight manifest. They won’t let you land without one.

— Helios Banking Inc.

Power up

Before you leave you must fill in your flight manifest. To do this, you must first set up a Crux node. You want to get started as quickly as possible so you decide to use Crux’s inbuilt standalone node.

You read the Crux manual entry for the standalone node to make sure this is OK.

If you want to get up and running with Crux fast, consider using the standalone node. There is a Crux inbuilt standalone node which is the most simple way to start playing with Crux. Bear in mind that this does not store any information beyond your session.

For persistent storage consider using RocksDB and for scale you should consider using Kafka.

(def crux
  (crux/start-standalone-node
   {:kv-backend "crux.kv.memdb.MemKv"
    :db-dir "data/db-dir"
    :event-log-dir "data/eventlog-1"}))

— Crux manual

Read More

You decide this is OK, and so define your Crux node.

You define the kv-backend as the built in standalone node. You still give locations for the db-dir (database directory) and event-log-dir (event log directory) knowing that Crux still needs these even though you are not implementing persistent storage right now.

Flight Manifest

You take a look around your ship and check the critical levels.

You read the manual entry for putting data into Crux.

Crux takes data in document form. Each document must be in Extensible Data Notation (edn) and each document must contain a unique :crux.db/id value. However, beyond those two requirements you have the flexibility to add whatever you like to your documents because Crux is schemaless.

— Crux manual

Read More

Just as you’re about to write your manifest, one of the porters passes you a secret note and asks you to deliver it to a martian named Kaarlang. They are certain you will meet Kaarlang on your travels and so you see no harm in delivering the note for them.

(def manifest
  {:crux.db/id :manifest
   :pilot-name "Johanna"
   :id/rocket "SB002-sol"
   :id/employee "22910x2"
   :badges "SETUP"
   :cargo ["stereo" "gold fish" "slippers" "secret note"]})

You put the manifest into Crux.

(crux/submit-tx crux [[:crux.tx/put manifest]])

This is put , one of Crux’s four transaction operations. Check that this was successful by asking Crux to show the whole entity.

(crux/entity (crux/db crux) :manifest)

Which returns the document you just put in:

=> {:crux.db/id :manifest,
      :pilot-name "Johanna"
      :id/rocket "SB002-sol"
      :id/employee "22910x2"
      :badges "SETUP"
      :cargo ["stereo" "gold fish" "slippers" "secret note"]}

Click on Pluto to take you to your first assignment.

FnYNbeN.png!web

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK