Skip to content

Instantly share code, notes, and snippets.

import Realm from "realm";
// Set your Schema
const ListingSchema = {
name: "Listing",
primaryKey: "_id",
properties: {
_id: "objectId",
location: "string",
price: "int",
init() {
loginPublisher
.receive(on: DispatchQueue.main)
.flatMap { user -> RealmPublishers.AsyncOpenPublisher in
self.shouldIndicateActivity = true
var realmConfig = user.configuration(partitionValue: "user=\(user.id)")
realmConfig.objectTypes = [User.self, Project.self]
return Realm.asyncOpen(configuration: realmConfig)
}
.receive(on: DispatchQueue.main)
import SwiftUI
import RealmSwift
let app = App(id: "tasktracker-xxxxx") // TODO: Set the Realm application ID
@main
struct swiftui_realmApp: SwiftUI.App {
@StateObject var state = AppState()
var body: some Scene {
@am-MongoDB
am-MongoDB / open-app.bash
Created February 19, 2021 10:36
Open task-tracker app in Xcode
git clone https://github.com/ClusterDB/task-tracker-swiftui.git
cd task-tracker-swiftui
pod install --repo-update
open task-tracker-swiftui.xcworkspace
@am-MongoDB
am-MongoDB / app-tech.md
Last active February 19, 2021 10:23
App Technologies
In 🔥 Out ❄️
Swift Objective C
SwiftUI UIKit
Combine RxSwift
Realm Core Data
MongoDB Realm Sync (where needed) Home-baked cross-platform data sync
{"collections": [
{
"_comment": "Customer collection",
"customerID": 123456,
"name": {
"title": "Mr",
"first": "Andrew",
"last": "Morgan"
},
"_passwordComment": "No need for user credentials as will use Google auth",
db.freedom.find(
{
acidTransaction: "NOW_ENABLED",
multiStatement: true,
familiarity: "like relational DB",
comfortFactor: "🧸 extra cuddly",
syntax: "oh so similar",
implementation: "even your gran could do it",
useCases: "wide open",
try: "MongoDB 4.0 today"
@am-MongoDB
am-MongoDB / MongoDB_insert.py
Created April 10, 2018 09:25
The code to add a single user using the MongoDB query language
from pymongo import MongoClient
def addUser(database, user):
return database.customers.insert_one(user).inserted_id
client = MongoClient(port=27017)
db=client.store
# This is the object that the application would be working with anyway and
@am-MongoDB
am-MongoDB / sql_insert.py
Created April 10, 2018 09:22
The code required to insert a single user using SQL
import mysql.connector
from mysql.connector import errorcode
def addUser(connection, user):
cursor = connection.cursor()
customerInsert = (
"INSERT INTO customer (first_name, last_name, email, "
"DOB, annual_spend) VALUES "
"(%(first)s, %(last)s, %(email)s, %(dob)s, %(spend)s)")
@am-MongoDB
am-MongoDB / index.js
Created March 13, 2017 08:58
Amazon Alexa skill to access MongoDB
"use strict";
var Alexa = require("alexa-sdk");
var request = require("request");
var config = require("./config.js");
exports.handler = function(event, context, callback) {
console.log("In handler");