Aista – Magic Cloud – Generate a CRUD app in seconds

Categories
SQL

Create an SQL Report API in 5 minutes

In addition to generating CRUD APIs, Aista Magic Cloud also allows you to generate API endpoints using nothing but SQL. The generator will take care of stuff such as authorisation, logging, generating the boiler plate code, etc. All you need to worry about is your SQL.

The whole point about Hyperlambda is that it’s a declarative programming language. When you have a declarative programming language, the computer can automatically generate a large portion of your code, through a process that’s similar to how you do it as you copy and paste code from StackOverflow. This implies that even though you can’t code in anything but SQL, you can still create Web API endpoints – Because Magic does everything for you, as long as you provide some SQL to it.

In the video below I am demonstrating the whole process. If you want to reproduce what I’m doing, signup at Hub and create your own cloudlet.

The code that Magic produces can be found below.


/*
 * Template for custom SQL HTTP request.
 * This file was automatically generated using Magic's CRUDifier.
 */
.arguments
   filter:string
.type:sql

// Opening up a database connection
data.connect:chinook
   database-type:sqlite

   // Parametrizing [data.select].
   add:x:./*/data.select
      get-nodes:x:@.arguments/*

   // Evaluating [xxx.select] slot.
   data.select:"\n/*\n * Script to aggregate records for each artist in chinook database.\n * Make sure you select the chinook database before execxuting the script.\n */\nselect ar.Name, count(*) as count\n  from Album al, Artist ar where al.ArtistId = ar.ArtistId and ar.Name like @filter\n  group by al.ArtistId\n  order by count desc\n  limit 25\n"
      database-type:sqlite

   /*
    * Checking if we should return a list of items, or only a
    * single item.
    */
   if
      .is-list:bool:true
      .lambda

         // Returning a list of items to caller.
         return-nodes:x:@data.select/*

   // Returning a single result to caller.
   return-nodes:x:@data.select/*/*

Thank you for reading 🙂