Skip to content

Instantly share code, notes, and snippets.

@codeopensrc
Last active June 10, 2016 19:47
Show Gist options
  • Save codeopensrc/182fb09951e25f8199e23635fb0ffe6b to your computer and use it in GitHub Desktop.
Save codeopensrc/182fb09951e25f8199e23635fb0ffe6b to your computer and use it in GitHub Desktop.
Example schema for Realm used in React Native

Schema example to my RealmWrapper.js and RealmExamples.md

You can find the RealmWrapper here and RealmExamples here

'use strict';


class Assigned {}
Assigned.schema = {
    name: "Assigned",
    primaryKey: "id",
    properties: {
        id: 'int',
        name: 'string',
        county: 'string',
        address: 'string',
        latlng: 'string',
        builder: 'string',
        status: {type: 'string', default: 'Assigned'}
    }
}

class Locked {}
Locked.schema = {
    name: "Locked",
    primaryKey: "id",
    properties: {
        id: 'int',
        name: 'string',
        county: 'string',
        address: 'string',
        latlng: 'string',
        builder: 'string',
        salesphone: 'string',
        status: {type: 'string', default: 'Locked'}
    }
}

class Img {}
Img.schema = {
    name: "Img",
    primaryKey: "id",
    properties: {
        id: 'string',
        parentId: {type: 'int', default: null},
        data: 'string'
    }
}

class SalesInfo {}
SalesInfo.schema = {
    name: "SalesInfo",
    primaryKey: "id",
    properties: {
        id: 'string',
        parentId: {type: 'string', default: null},
        Date: {type: 'string', default: ''},
        "Units Zoned": {type: 'string', default: ''},
        "Units Released": {type: 'string', default: ''},
        "Units Sold": {type: 'string', default: ''},
        "Closed Escrows": {type: 'string', default: ''},
        "Stand Inventory": {type: 'string', default: ''},
        "Under Construction": {type: 'string', default: ''},
        "Improved Lots": {type: 'string', default: ''},
        "Unreleased Inventory": {type: 'string', default: ''}
    }
}

class Survey {}
Survey.schema = {
    name: "Survey",
    primaryKey: "id",
    properties: {
        id: 'string',
        parentId: {type: 'int', default: null},
        "Hoa Master": {type: 'string', default: ''},
        "Hoa Sub": {type: 'string', default: ''},
        "Traffic": {type: 'string', default: ''},
        "Broker Coop": {type: 'string', default: ''},
        "Below Market Rate Units": {type: 'string', default: ''},
        "Financing": {type: 'string', default: ''},
        "Sellout Date": {type: 'string', default: ''},
        "Comments": {type: 'string', default: ''},
        salesinfo: {type: 'list', objectType: 'SalesInfo'}
    }
}

class Floorplan {}
Floorplan.schema = {
    name: "Floorplan",
    primaryKey: "id",
    properties: {
        id: 'string',
        parentId: {type: 'int', default: null},
        Name: {type: 'string', default: ''},
        Price: {type: 'string', default: ''},
        "Updated Price": {type: 'string', default: ''},
        Latest: {type: 'string', default: ''},
        Incentive: {type: 'string', default: '0'},
        Range: {type: 'string', default: '0'},
        "Unit Mix": {type: 'string', default: '0'},
        Available: {type: 'string', default: '0'},
        images: {type: 'list', objectType: 'Img'}
    }
}

class Development {}
Development.schema = {
    name: 'Development',
    primaryKey: 'id',
    properties: {
        id: 'int',
        name: {type: 'string', default: ''},
        builder: {type: 'string', default: ''},
        area: {type: 'string', default: ''},
        city: {type: 'string', default: ''},
        county: {type: 'string', default: ''},
        address: {type: 'string', default: ''},
        zip: {type: 'string', default: ''},
        latlng: {type: 'string', default: ''},
        salesphone: {type: 'string', default: ''},
        adminnotes: {type: 'string', default: ''},
        floorplans: {type: 'list', objectType: 'Floorplan'},
        images: {type: 'list', objectType: 'Img'},
        survey: {type: 'Survey', default: null},
    }
}
export default [Assigned, Locked, Img, SalesInfo, Survey, Floorplan, Development]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment