CodeMash
  • 🚀Backend as a service
  • 🦄Roadmap
  • 🍕Release Notes
  • Installation
    • Managed Service
    • 🏗️AWS-CDK
    • 🏗️Azure
    • 🏗️Docker
    • 🏗️GC
    • 🏗️Terraform
  • dashboard
    • CodeMash Cloud
    • Project
    • Membership
      • Users
      • Roles
      • Policies
      • Triggers
      • Integrations
        • Apple
        • Azure
        • Facebook
        • Google
        • Twitter
      • Settings
    • Database
      • Collections
        • Schema
          • From Template
          • Structure
        • Tabs
        • Triggers
        • Indexes
        • Shared Forms
      • Taxonomies
        • Terms
        • Schema
        • Settings
      • Aggregation
      • Imports
      • Exports
      • Backups
    • Files
      • Integrations
        • CodeMash
        • S3 Bucket
    • Notifications
      • Push
        • Push Templates
        • Push Templates API
        • Push Notifications
        • Push Notifications API
        • Devices
        • Devices API
        • Integrations
          • Firebase
          • One Signal
          • Expo
      • Email
        • Email Templates
        • Emails
        • Integrations
          • AWS SES
          • Twilio Sendgrid
          • Mailgun
      • 🏗️Server events
      • 🏗️Sms
    • Payments
      • Integrations
        • Apple Pay
        • Google Pay
        • Stripe
        • Kevin.
        • Paysera
        • Decta
    • Scheduler
    • Logs & Monitoring
    • Code
      • Functions
        • Function Inputs
        • Function Templates
          • Node.js
          • Python
          • Ruby
          • Java
          • Go
          • .NET Core
      • CodeMash Functions
        • Google Functions
          • Google Calendar
          • Google Gmail
        • Microsoft Functions
          • Microsoft 365 Users
          • Microsoft 365 Calendar
        • Collection Find
        • Collection Update
        • Users Find
        • Image Resize
        • Html To Pdf
        • Word Document
        • Barcode
        • QR Code
        • Send Email
        • Send Notification
        • Email Reminder
        • Notification Reminder
      • Integrations
        • AWS Lambda
        • Google Cloud Functions
        • Azure Functions
  • Other Topics
    • Apple
      • Developer Portal
      • Bundle Identifier
      • Team ID
      • Service ID
      • Key ID
    • Triggers
    • Tokens Binding
      • Project Tokens
      • Initiator Tokens
      • Receiver Tokens
      • Request Tokens
      • Operation based tokens
      • Template Functions
    • Search parameters
      • Paging
      • Filter
      • Sort
      • Projection
    • data-models
    • Errors
  • SDK
    • Node.js
    • TypeScript
    • .NET
    • 🏗️Go Lang
    • 🏗️Flutter
    • 🏗️Swift
    • 🏗️Kotlin
  • CLI
    • 🏗️CodeMash CLI
  • API
    • Get Started
    • Prerequisites
    • How to test?
    • Cors
    • Project
    • Membership
      • Authentication
      • Users
    • Database
      • Collections
        • Aggregate
        • Change Responsibility
        • Count
        • Delete
        • Delete Many
        • Distinct
        • Find
        • Find One
        • Insert
        • Insert Many
        • References
        • Replace
        • Update
        • Update Many
      • Taxonomies
        • Find
    • Files
    • Code
    • Notifications
      • Push
      • Emails
      • Server Events
      • 🏗️Sms
    • Payments
    • Scheduler
    • Logs & Monitoring
Powered by GitBook
On this page
  • Using SDK
  • Working with Database Service

Was this helpful?

Edit on GitHub
  1. dashboard

Database

Create a database with No Code. You automatically will get access to the data in your collection over fully managed and secure https endpoints

PreviousSettingsNextCollections

Last updated 2 years ago

Was this helpful?

CodeMash Database service provides many operations for database management like CRUD operations, schema builder, and data validation.

When you enable a database service in your we create a new MongoDb database for you. When that is done you are able to create collections using our provided tools in the dashboard. After you create a collection you can start adding records through the dashboard or calling to API endpoints.

Features included in database service:

  1. Collections - just like any database collection.

  2. Taxonomies - special kind of collections used mostly for basic select type data.

  3. Imports - importing records to collections.

  4. Exports - exporting records from collections.

  5. Backups - dumping and restoring collections.

Using SDK

If you decide to use one of our provided SDK, the following code shows how to initialize database service.

var projectId = Guid.Parse("{YOUR_PROJECT_ID}");
var apiKey = "{YOUR_SECRET_KEY}";

var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);

Here Person is a class which extends the interface IEntity. The example below shows a class extendingEntityclass which extendsIEntityinterface. The attributeCollectionNameis a helper for a client. It takes one parameter - the name of your collection in CodeMash.

[Collection("persons")]
public class Person : Entity
{
    [Field("name")]
    public string Name { get; set; }
}

Here UniqueName is an attribute that is used to set the unique name of a field (the name that is used inside a database). This name can be found in your collection, field details. If this attribute is not used, then your field will be serialized and deserialized as a lowercase property name.

import { db } from 'codemash';
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';

$client = new CodemashClient($secretKey, $projectId);
$codemashDb = new CodemashDb($client);
using System;
using CodeMash.Client;
using CodeMash.Repository;
using MongoDB.Driver;

namespace ConsoleApplication
{
    [CollectionName("persons")]
    public class Person : Entity
    {
        public string Name { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            // 1. Get your Project ID and Secret Key
            var projectId = Guid.Parse("{YOUR_PROJECT_ID}");
            var apiKey = "{YOUR_SECRET_KEY}";
            
            // 2. Create a general client for API calls
            var client = new CodeMashClient(apiKey, projectId);
            
            // 3. Create a service object
            var dbService = new CodeMashRepository<Person>(client);
            
            // 4. Call an API method
            var filter = Builders<Person>.Filter.Eq(x => x.Name, "John");
            var result = dbService.Find(filter);
        }
    }
}
export async function getHolidaysOfEmployee(userId) {
    
    const filter = JSON.stringify({
        application_user: userId,
        status: 'Approved',
    });
    
    // gets first 100 records - all approved holidays sorted out by start date 
    const response = 
        await db.getRecords('holidays', 0, 100, { start: -1 }, filter);
    
    return response;
}
use Codemash\CodemashClient;
use Codemash\CodemashDb;

class CodemashService
{
    protected CodemashDb $codemashDb;
    protected string $collectionName = '{YOUR_COLLECTION_NAME}';

    public function __construct()
    {
        $secretKey = '{YOUR_SECRET_KEY}';
        $projectId = '{YOUR_PROJECT_ID}';

        $client = new CodemashClient($secretKey, $projectId);
        $this->codemashDb = new CodemashDb($client);
    }

    public function getEmployees()
    {
        $responseData = $this->codemashDb->findMany([
        	'collectionName' => 'employees',
        	'filter' => [
        		'address' => 'New York',
        	],
        ]);
    }
}

Working with Database Service

The following links explore the usage of database service:

The following are examples of database using different languages and frameworks.

CodeMash dashboard page
SDK
Collections
Taxonomies
Imports
Exports
Backups