Skip to main content
Zeromagic supports a range of database methods to perform CRUD (Create, Read, Update, Delete) operations on data. Available methods include readOne, readMany, createOne, createMany, updateOne, updateMany, deleteOne, and deleteMany, providing comprehensive support for data management tasks.

Read Operations

readOne & readMany

The ReadOne and ReadMany both has same syntax but ReadOne returns only single object as dict where ReadMany returns multiple objects as list. The query object must contain the container and filter properties. fields property is optional which returns a particular fields of created records.
//Let's fetch list of employees from 'employees' container/table where departments must be in Marketting,Developers and sorting by joined_at in descending order
{
  "container": "employees",
  "fields": ["id","age",{"dept":"department"},{"name": "full_name"}],
  "filter": {
    "@sort": {
      "key": "joined_at",
      "order": "desc"
    },
    "department": {
      "@in": ["Marketting", "Developers"],
    }
  }
}

Create Operations

createOne

The CreateOne method is used to create a single item in the specified container. The query object must contain the container and item properties. fields property is optional which returns a particular fields of created records.
//Let's insert a new employee data into 'employee' container/table and return the id,name after creation
{
    "container": "employee",
    "item": {
        "id": "1",
        "name": "Zeromagic Genie",
        "age": 25,
        "department" : "Developers",
        "country" : "India"
    },
    "fields":["id","name"]
}

createMany

The CreateMany method is used to create multiple items in the specified container. The query object must contain the container and items properties. fields property is optional which returns a particular fields of created records.
//Let's insert multiple employee data into 'employee' container/table and return the id,name after creation
{
    "container": "employee",
    "items": [
        {
            "id": "1",
            "name": "Zeromagic Genie",
            "age": 25,
            "department" : "Developers",
            "country" : "India"
        },
        {
            "id": "2",
            "name": "Alibaba Genie",
            "age": 22,
            "department" : "Marketting",
            "country" : "USA"
        },
    ]
    "fields":["id","name"]
}

Update Operations

updateOne

The updateOne method is used to update a single item in the specified container with id field. The query object must contain the container, id and update properties. fields property is optional which returns a particular fields of updated records.
//Let's update the work_location of employee id=1 as Chennai
{
    "container": "employee",
    "id": "1",
    "update": {
        "work_location" : "Chennai"
    }
    "fields":["id","name",{"location":"work_location"}]
}

updateMany

The updateMany method is used to update multiple item in the specified container. The query object must contain the container, filter and update properties. fields property is optional which returns a particular fields of updated records.
//Let's update the all the employees with engineering level as SDE-1
{
    "container": "employee",
    "filter" : {},
    "update": {
        "engineer_level" : "SDE-1"
    }
    "fields":["id","name"]
}

Delete Operations

deleteOne

The deleteOne method is used to delete a single item in the specified container with id field. The query object must contain the container, id properties. fields property is optional which returns a particular fields of deleted records.
//Let's delete the employee with id=1
{
    "container": "employee",
    "id": "1",
    "fields":["id","name",{"location":"work_location"}]
}

deleteMany

The deleteMany method is used to delete mutliple items in the specified container. The query object must contain the container, filter properties. fields property is optional which returns a particular fields of deleted records.
//Let's delete the employee where work_location='Chennai'
{
    "container": "employee",
    "filter" : {
        "work_location" : {
            "@eq" : "Chennai"
        }
    },
    "fields":["id"]
}