DEV Community

Cover image for CRUD with Nucleoid (Low-code Backend)
Can Mingir for Nucleoid

Posted on

CRUD with Nucleoid (Low-code Backend)

Nucleoid Low-code Framework works with underlying declarative runtime environment that re-renders very same JavaScript codes makes a connections in the graph and eventually save the JavaScript state so that it doesn't require external database.

Features

  • 👽 lets developers build APIs with the help of AI (Lots of Graph)
  • ❤ works with underlying declarative runtime environment
  • 🤘 the runtime also comes with built-in datastore

Quick Setup

const nucleoid = require("nucleoidjs"); // npm install nucleoidjs
const app = nucleoid();
Enter fullscreen mode Exit fullscreen mode

Create

let's start with creating User class and its first user object with this 👇

class User {
  constructor(name) {
    this.name = name;
  }
}

nucleoid.register(User);

app.post("/users", (req) => {
  const name = req.body.name;
  return new User(name);
});
Enter fullscreen mode Exit fullscreen mode

🌵 The reason why you don't need external database is Nucleoid runtime manages and stores JavaScript state. Every time when there are statements run through the runtime, Nucleoid runtime adjusts the AI graph and stores within runtime-managed fs.

Read

app.get("/users/:id", (req) => {
  const id = req.params.id;
  return User[id];
});
Enter fullscreen mode Exit fullscreen mode

When a class like User registered, the runtime creates shortcut array for its instances, you can query or use the id (var name) of the instance for the access later down. Alternatively, you can do like this too User.find(user => user.id === id)

Update & Delete

app.post("/users/:id", (req) => {
  const id = req.params.id;
  const name = req.body.name;

  const user = User[id];

  if (user) {
    user.name = name;
    return user;
  }
});

app.delete("/users/:id", (req) => {
  const id = req.params.id;
  delete User[id];
});
Enter fullscreen mode Exit fullscreen mode

Similar to examples above, it works with vanilla JavaScript, and the runtime re-renders and manages the JavaScript state. Additionally, you can write up some business logic in JavaScript as well. For example, you may say if (user.name.length < 3) { throws "INVALID_USER" } if you want certain limitation on users' names.

Query

nucleoidjs package also opens up terminal channel in order to run statements like SQL

Terminal Screenshot

Nucleoid IDE (OpenAPI Editor)

We are also building online OpenAPI editor that helps to build up very same APIs with the user interface. It is especially designed for OpenAPI integration and also has a connection to CodeSandbox so that you can easily run your projects on the sandbox.

Screenshot 1


Thanks to declarative programming, we have a brand-new approach to data and logic. As we are still discovering what we can do with this powerful programming model, please join us with any types of contribution!


Learn more at https://github.com/NucleoidJS/Nucleoid

Nucleoid Logo

Discussion (1)

Collapse
joestomopolous profile image
joestomopolous

Clapping