-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Clean up unused files (Test)" (#2482)
Reverts #2474
- Loading branch information
Showing
1,387 changed files
with
24,793 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
realm.write(() => { | ||
// Delete all objects from the realm. | ||
realm.deleteAll(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[realm transactionWithBlock:^() { | ||
// Delete all objects from the realm. | ||
[realm deleteAllObjects]; | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
RLMResults *projects = [Project allObjectsInRealm:realm]; | ||
RLMResults *tasks = [Task allObjectsInRealm:realm]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
38
source/examples/Migrations/LocalMigration/LocalMigration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
source/examples/Migrations/LocalMigration/LocalMigration.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
source/examples/Migrations/LocalMigration/LocalMigration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?" | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.