Giter Club home page Giter Club logo

fauna-java's Introduction

fauna-java

This is a sample application that demonstrates basics operations we can perform in FQL by using a Fauna client for Java

Prerequisites

The only prerequisite you need to run this application is JDK:
https://openjdk.java.net/install/index.html

Supported Java versions:

  • 11 and higher

You can do all operations on the database from the fauna dashboard:
https://dashboard.fauna.com/
Alternatively, you can use a fauna-shell app:
https://github.com/fauna/fauna-shell

Fauna database structure

You'll need to create 2 collections:

  • Categories (name: string)
  • Products (name: string, price: float, description: string, category_id: ref_Categories, quantity: int)

Follow the next steps to create collections and documents:

  • Sign up for free or log in at dashboard.fauna.com.
  • Click [CREATE DATABASE], name it "shopapp", select a region group (e.g., "Classic"), and click [CREATE]
  • Click the [SECURITY] tab at the bottom of the left sidebar, and [NEW KEY].
  • Create a Key with the default Role of "Admin" selected, you'll need to add this key to one of the environment variable to start the app, you'll see the name of that variable in the following section
  • Navigate to your "shopapp" by just clicking on it on the main page of the fauna dashboard
  • Click "New Collection", and provide a name for it, i.e. "Categories", and click "Save"
  • Do the same and create the "Products" collection
  • Navigate to the "Collections" menu and choose "Categories" collection
  • Click "New Document", in the opened page add some document, for example:
{
    name: "Books"
}
  • Create several documents
  • Do the same for "Products" collection (notice that we've also added a reference to "Categories" collection):
{
    name: "Some product name",
    price": 152.11,
    description: "Some description",
    category_id: Ref(Collection("Categories"), "287626591762121219"),
    quantity: 5,
}

Make sure to add your own "category_id" reference, to retrieve it you can click "Collections" in the fauna dashboard, and choose one of the documents in "Categories" collection.

  • You can populate more data for those 2 collections if you want

Running the application locally

The application uses fauna managed database service, you'll need to export 2 environment variables to access it (getting a secret key is described in the previous section):

export FAUNA_DB_HOST=https://db.fauna.com
export FAUNA_SECRET_KEY=your-secret-key

This is a spring boot application, and you can start a server by running:

./gradlew bootRun

After that server should be available at http://localhost:8080/

Rest endpoints

Swagger UI

Swagger UI is automatically started as well, so you can check all the available endpoints here:
http://localhost:8080/swagger-ui/

fauna-java's People

Contributors

parkhomenko avatar

Stargazers

 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.