Skip to content

Commit

Permalink
Revert "Clean up unused files (Test)" (#2482)
Browse files Browse the repository at this point in the history
Reverts #2474
  • Loading branch information
cbush authored Jan 11, 2023
1 parent 9a86831 commit 804c8ba
Show file tree
Hide file tree
Showing 1,387 changed files with 24,793 additions and 0 deletions.
13 changes: 13 additions & 0 deletions source/examples/CRUD/BatchUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
realm.write(() => {
// Create someone to take care of some dogs.
const ali = realm.create("Person", { id: 1, name: "Ali" });

// Find dogs younger than 2.
const puppies = realm.objects("Dog").filtered("age < 2");

// Loop through to update.
puppies.forEach(puppy => {
// Give all puppies to Ali.
puppy.owner = ali;
});
});
8 changes: 8 additions & 0 deletions source/examples/CRUD/Create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Declare the instance.
let dog;

// Open a transaction.
realm.write(() => {
// Assign a newly-created instance to the variable.
dog = realm.create("Dog", { name: "Max", age: 5 });
});
7 changes: 7 additions & 0 deletions source/examples/CRUD/Delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
realm.write(() => {
// Delete the dog from the realm.
realm.delete(dog);

// Discard the reference.
dog = null;
});
7 changes: 7 additions & 0 deletions source/examples/CRUD/Delete.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[realm transactionWithBlock:^() {
// Delete the instance from the realm.
[realm deleteObject:dog];

// Discard the reference.
dog = nil;
}];
4 changes: 4 additions & 0 deletions source/examples/CRUD/DeleteAll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
realm.write(() => {
// Delete all objects from the realm.
realm.deleteAll();
});
4 changes: 4 additions & 0 deletions source/examples/CRUD/DeleteAll.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[realm transactionWithBlock:^() {
// Delete all objects from the realm.
[realm deleteAllObjects];
}];
4 changes: 4 additions & 0 deletions source/examples/CRUD/DeleteAllOfClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
realm.write(() => {
// Delete all instances of Dog from the realm.
realm.deleteModel("Dog");
});
5 changes: 5 additions & 0 deletions source/examples/CRUD/DeleteAllOfClass.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[realm transactionWithBlock:^() {
// Delete all instances of Dog from the realm.
RLMResults<Dog *> *allDogs = [Dog allObjectsInRealm:realm];
[realm deleteObjects:allDogs];
}];
7 changes: 7 additions & 0 deletions source/examples/CRUD/DeleteCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
realm.write(() => {
// Find dogs younger than 2 years old.
const puppies = realm.objects("Dog").filtered("age < 2");

// Delete the collection from the realm.
realm.delete(puppies);
});
7 changes: 7 additions & 0 deletions source/examples/CRUD/DeleteCollection.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[realm transactionWithBlock:^() {
// Find dogs younger than 2 years old.
RLMResults<Dog *> *puppies = [Dog objectsInRealm:realm where:@"age < 2"];

// Delete all objects in the collection from the realm.
[realm deleteObjects:puppies];
}];
5 changes: 5 additions & 0 deletions source/examples/CRUD/Objects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Query realm for all instances of the "Project" type.
const projects = realm.objects("Project");

// Query realm for all instances of the "Task" type.
const tasks = realm.objects("Task");
2 changes: 2 additions & 0 deletions source/examples/CRUD/Objects.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RLMResults *projects = [Project allObjectsInRealm:realm];
RLMResults *tasks = [Task allObjectsInRealm:realm];
17 changes: 17 additions & 0 deletions source/examples/CRUD/Sort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const projects = realm.objects("Project");

// Sort projects by name in ascending order
let projectsSorted = projects.sorted("name");

// Sort projects by name in descending order
projectsSorted = projects.sorted("name", true);

const tasks = realm.objects("Task");

// Sort by priority in descending order and then by name alphabetically
let tasksSorted = tasks.sorted([["priority", true], ["name", false]]);

// You can also sort on the members of linked objects. In this example,
// we sort the dogs by dog's owner's name.
const dogs = realm.objects("Dog");
dogs = dogs.sorted("owner.name");
6 changes: 6 additions & 0 deletions source/examples/CRUD/Sort.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RLMResults *projectsSorted = [projects sortedResultsUsingKeyPath:@"name" ascending:NO];

// You can also sort on the members of linked objects. In this example,
// we sort the dogs by dog's owner's name.
RLMResults *dogs = [Dog allObjectsInRealm:realm];
RLMResults *ownersByName = [dogs sortedResultsUsingKeyPath:@"owner.name" ascending:YES];
12 changes: 12 additions & 0 deletions source/examples/CRUD/Transaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Open the default realm.
var realm = Realm.GetInstance();

// Open a thread-safe transaction.
realm.Write(() =>
{
// Make any writes within this code block.
// Realm automatically cancels the transaction
// if this code throws an exception. Otherwise,
// Realm automatically commits the transaction
// after the end of this code block.
});
11 changes: 11 additions & 0 deletions source/examples/CRUD/Transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Open the default realm with the relevant schema.
const realm = await Realm.open({ schema: [DogSchema] });

// Open a transaction.
realm.write(() => {
// ... Make changes ...
// Realm automatically cancels the transaction if this
// code block throws an exception. Otherwise, Realm
// automatically commits the transaction at the end
// of the code block.
});
10 changes: 10 additions & 0 deletions source/examples/CRUD/Transaction.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Open the default realm.
RLMRealm *realm = [RLMRealm defaultRealm];

// Open a thread-safe transaction.
[realm transactionWithBlock:^() {
// ... Make changes ...
// Realm automatically cancels the transaction in case of exception.
// Otherwise, Realm automatically commits the transaction at the
// end of the code block.
}];
14 changes: 14 additions & 0 deletions source/examples/CRUD/TransactionCounterexample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// BAD EXAMPLE -- avoid this!

// The transaction in a using block is automatically
// disposed at the end of the block, which rolls back
// any uncommitted changes.
using (var transaction = realm.BeginWrite())
{
// ... Make changes ...

// Manually commit the transaction upon success.
// If you forget to do this, your changes will be
// lost at the end of your block.
transaction.Commit();
}
6 changes: 6 additions & 0 deletions source/examples/CRUD/TransactionCounterexample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// BAD EXAMPLE -- avoid this!

realm.beginTransaction();
// ... Make changes ...
// If an exception is thrown here, the transaction remains open!
realm.commitTransaction();
6 changes: 6 additions & 0 deletions source/examples/CRUD/TransactionCounterexample.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// BAD EXAMPLE -- avoid this!

[realm beginWriteTransaction];
// ... Make changes ...
// If an exception is thrown here, the transaction remains open!
[realm commitWriteTransaction];
10 changes: 10 additions & 0 deletions source/examples/CRUD/Update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Open a transaction.
realm.write(() => {
// Get a dog to update.
const dog = realm.objects("Dog")[0];

// Update some properties on the instance.
// These changes are saved to the realm.
dog.name = "Wolfie";
dog.age += 1;
});
10 changes: 10 additions & 0 deletions source/examples/CRUD/Update.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Open a thread-safe transaction.
[realm transactionWithBlock:^() {
// Get a dog to update.
Dog *dog = [[Dog allObjectsInRealm: realm] firstObject];

// Update some properties on the instance.
// These changes are saved to the realm.
dog.name = @"Wolfie";
dog.age += 1;
}];
12 changes: 12 additions & 0 deletions source/examples/CRUD/Upsert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
realm.write(() => {
// Add a new person to the realm. Since nobody with ID 1234
// has been added yet, this adds the instance to the realm.
const drew = realm.create("Person", { id: 1234, name: "Drew" }, "modified");

// Judging by the ID, it's the same person, just with a different name.

// If an object exists, setting the third parameter (`updateMode`) to
// "modified" only updates properties that have changed, resulting in
// faster operations.
const andy = realm.create("Person", { id: 1234, name: "Andy" }, "modified");
});
11 changes: 11 additions & 0 deletions source/examples/CRUD/Upsert.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[realm transactionWithBlock:^() {
Person *drew = [[Person alloc] initWithValue:@{@"ID": @1234, @"name": @"Drew"}];
// Add a new person to the realm. Since nobody with ID 1234
// has been added yet, this adds the instance to the realm.
[realm addOrUpdateObject:drew];

Person *andy = [[Person alloc] initWithValue:@{@"ID": @1234, @"name": @"Andy"}];
// Judging by the ID, it's the same person, just with a different name.
// This overwrites the original entry (i.e. Drew -> Andy).
[realm addOrUpdateObject:andy];
}];
6 changes: 6 additions & 0 deletions source/examples/CRUD/delete-an-object-with-a-relationship.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
realm.write(() => {
// Delete all of Ali's dogs.
realm.delete(ali.dogs);
// Delete Ali.
realm.delete(ali);
});
62 changes: 62 additions & 0 deletions source/examples/EmbeddedObjects/DefineEmbeddedObjects.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Define the embedded object
@interface Address : RLMEmbeddedObject
@property NSString *street;
@property NSString *city;
@property NSString *country;
@property NSString *postalCode;
@end

// Enable use in RLMArray
RLM_ARRAY_TYPE(Address)

@implementation Address
@end

// A Contact has one embedded address
@interface Contact : RLMObject
@property RLMObjectId *_id;
@property NSString *name;

// Define a single embedded object
@property Address *address;
@end

@implementation Contact
+ (NSString *)primaryKey {
return @"_id";
}

+ (NSArray<NSString *> *)requiredProperties {
return @[@"_id", @"name"];
}

+ (NSDictionary *)defaultPropertyValues {
return @{@"_id": [RLMObjectId objectId]};
}

+ (instancetype)contactWithName:(NSString *)name {
Contact *instance = [[Contact alloc] init];
if (instance) {
instance.name = name;
}
return instance;
}
@end

// A Business has multiple embedded addresses
@interface Business : RLMObject
@property RLMObjectId *_id;
@property NSString *name;
// Define an array of embedded objects
@property RLMArray<Address *><Address> *addresses;
@end

@implementation Business
+ (NSString *)primaryKey {
return @"_id";
}

+ (NSArray<NSString *> *)requiredProperties {
return @[@"_id", @"name"];
}
@end
38 changes: 38 additions & 0 deletions source/examples/Migrations/LocalMigration/LocalMigration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var config = new RealmConfiguration
{
SchemaVersion = 4,
MigrationCallback = (migration, oldSchemaVersion) =>
{
var oldPeople = migration.OldRealm.All("Person");
var newPeople = migration.NewRealm.All("Person");

// Migrate Person objects
for (var i = 0; i < newPeople.Count(); i++)
{
var oldPerson = oldPeople.ElementAt(i);
var newPerson = newPeople.ElementAt(i);

// Changes from version 1 to 2 (adding LastName) will occur automatically when Realm detects the change

// Migrate Person from version 2 to 3: replace FirstName and LastName with FullName
// LastName doesn't exist in version 1
if (oldSchemaVersion < 2)
{
newPerson.FullName = oldPerson.FirstName;
}
else if (oldSchemaVersion < 3)
{
newPerson.FullName = $"{oldPerson.FirstName} {oldPerson.LastName}";
}

// Migrate Person from version 3 to 4: replace Age with Birthday
if (oldSchemaVersion < 4)
{
var birthYear = DateTimeOffset.UtcNow.Year - oldPerson.Age;
newPerson.Birthday = new DataTimeOffset(birthYear, 1, 1, 0, 0, 0, TimeSpan.Zero);
}
}
}
};

var realm = Realm.GetInstance(config);
18 changes: 18 additions & 0 deletions source/examples/Migrations/LocalMigration/LocalMigration.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// In [AppDelegate didFinishLaunchingWithOptions:]
RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
config.schemaVersion = 2;
config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {
if (oldSchemaVersion < 1) {
// The enumerateObjects:block: method iterates over every
// 'Person' object stored in the Realm file
[migration enumerateObjects:Person.className
block:^(RLMObject *oldObject, RLMObject *newObject) {

// combine name fields into a single field
newObject[@"fullName"] = [NSString stringWithFormat:@"%@ %@",
oldObject[@"firstName"],
oldObject[@"lastName"]];
}];
}
};
[RLMRealmConfiguration setDefaultConfiguration:config];
31 changes: 31 additions & 0 deletions source/examples/Migrations/LocalMigration/LocalMigration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Person {
public name: string = "";
public birthdate: Date = new Date();
public dogs: Realm.List<Dog> = [];

public static schema: Realm.ObjectSchema = {
name: "Person",
properties: {
name: "string",
birthdate: "date",
dogs: "Dog[]"
}
};
}

class Dog {
public name: string = "";
public age: number = 0;
public breed?: string;
public owner?: Person;

public static schema: Realm.ObjectSchema = {
name: "Dog",
properties: {
name: "string",
age: "int",
breed: "string?",
owner: "Person?"
}
}
};
5 changes: 5 additions & 0 deletions source/examples/Migrations/PersonClassV1/PersonClassV1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Person : RealmObject
{
public string FirstName { get; set; }
public int Age { get; set; }
}
5 changes: 5 additions & 0 deletions source/examples/Migrations/PersonClassV1/PersonClassV1.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@interface Person : RLMObject
@property NSString *firstName;
@property NSString *lastName;
@property int age;
@end
5 changes: 5 additions & 0 deletions source/examples/Migrations/PersonClassV1/PersonClassV1.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Person: Object {
@objc dynamic var firstName = ""
@objc dynamic var lastName = ""
@objc dynamic var age = 0
}
Loading

0 comments on commit 804c8ba

Please sign in to comment.