Realm은 Flutter용 공식 모바일 데이터베이스 SDK로, SQLite 및 키-값 저장소의 빠르고 유연하며 확장 가능한 대안을 제공합니다. 실시간 동기화, 반응형 데이터 바인딩, Dart/Flutter 앱과의 원활한 통합을 지원합니다. Realm은 Android, iOS, macOS, Windows, Linux 등 여러 플랫폼을 지원하여 오프라인 우선 애플리케이션을 개발하고 장치 간 일관된 데이터를 유지할 수 있게 해줍니다. 직관적인 API는 데이터 모델링과 쿼리를 간편하게 만들어주며, 내장된 암호화 기능으로 데이터 보안을 보장합니다. 고성능과 낮은 지연 시간을 위해 설계되어 동적이고 데이터 중심의 애플리케이션에 이상적입니다.
사용 사례
오프라인 우선 모바일 앱
실시간 데이터 동기화
크로스 플랫폼 데이터 지속성
고성능 데이터 액세스
안전한 로컬 데이터 저장
주요 기능
실시간 데이터 업데이트
반응형 프로그래밍 지원
크로스 플랫폼 호환성
내장형 암호화
직관적인 객체 지향 API
적합한 대상
모바일 앱 개발자
데이터 집약형 응용 프로그램
오프라인 기능이 필요한 앱
크로스 플랫폼 솔루션을 구축하는 팀
빠른 로컬 데이터 접근이 필요한 프로젝트
고려 사항
객체 지향 데이터 모델링에 대한 이해가 필요합니다
SQL에 비해 쿼리 복잡도가 제한됨
마이그레이션 전략은 신중한 계획이 필요합니다
새 사용자를 위한 학습 곡선
동기화(선택 사항)에 Realm의 클라우드 서비스 의존
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
[!WARNING]
We announced the deprecation of Atlas Device Sync + Realm SDKs in September 2024. For more information please see:
For a version of realm-dart without sync features, install version 20 or see the community branch.
Realm is a mobile database that runs directly inside phones, tablets or wearables.
This repository holds the source code for the Realm SDK for Flutter™ and Dart™.
Features
Mobile-first: Realm is the first database built from the ground up to run directly inside phones, tablets, and wearables.
Simple: Realm’s object-oriented data model is simple to learn, doesn’t need an ORM, and the API lets you write less code to get apps up & running in minutes.
Modern: Realm supports latest Dart and Flutter versions and is built with sound null-safety.
Fast: Realm is faster than even raw SQLite on common operations while maintaining an extremely rich feature set.
import'package:realm/realm.dart'; // import realm packagepart'app.realm.dart'; // declare a part file.@RealmModel() // define a data model class named `_Car`.class_Car{
lateString make;
lateString model;
int? kilometers = 500;
}
Generate RealmObject class Car from data model class _Car.
dart run realm generate
Open a Realm and add some objects.
var config = Configuration.local([Car.schema]);
var realm = Realm(config);
var car = Car("Tesla", "Model Y", kilometers: 5);
realm.write(() {
realm.add(car);
});
Query objects in Realm.
var cars = realm.all<Car>();
Car myCar = cars[0];
print("My car is ${myCar.make} model ${myCar.model}");
cars = realm.all<Car>().query("make == 'Tesla'");
Generate RealmObject class Item from data model class _Item.
On Flutter use dart run realm to run realm package commands
dart run realm generate
A new file catalog.realm.dart will be created next to the catalog.dart.
*The generated file should be committed to source control
Use the RealmObject class Item with Realm.
// Create a Configuration objectvar config = Configuration.local([Item.schema]);
// Opean a Realmvar realm = Realm(config);
var myItem = Item(0, 'Pen', price: 4);
// Open a write transaction
realm.write(() {
realm.add(myItem);
var item = realm.add(Item(1, 'Pencil')..price = 20);
});
// Objects `myItem` and `item` are now managed and persisted in the realm// Read object properties from realmprint(myItem.name);
print(myItem.price);
// Update object properties
realm.write(() {
myItem.price = 20;
myItem.name = "Special Pencil";
});
// Get objects from the realm// Get all objects of typevar items = realm.all<Item>();
// Get object by indexvar item = items[1];
// Get object by primary keyvar itemByKey = realm.find<Item>(0);
// Filter and sort objectvar objects = realm.query<Item>("name == 'Special Pencil'");
var name = 'Pen';
objects = realm.query<Item>(r'name == $0', [name]);
// Close the realm
realm.close();
Full contents of catalog.dart
import'package:realm/realm.dart';
part'catalog.realm.dart';
@RealmModel()
class_Item{
@PrimaryKey()
lateint id;
lateString name;
int price = 42;
}
// Create a Configuration objectvar config = Configuration.local([Item.schema]);
// Open a Realmvar realm = Realm(config);
var myItem = Item(0, 'Pen', price: 4);
// Open a write transaction
realm.write(() {
realm.add(myItem);
var item = realm.add(Item(1, 'Pencil')..price = 20);
});
// Objects `myItem` and `item` are now managed and persisted in the realm// Read object properties from realmprint(myItem.name);
print(myItem.price);
// Update object properties
realm.write(() {
myItem.price = 20;
myItem.name = "Special Pencil";
});
// Get objects from the realm// Get all objects of typevar items = realm.all<Item>();
// Get object by indexvar item = items[1];
// Get object by primary keyvar itemByKey = realm.find<Item>(0);
// Filter and sort objectvar objects = realm.query<Item>("name == 'Special Pencil'");
var name = 'Pen';
objects = realm.query<Item>(r'name == $0', [name]);
// Close the realm
realm.close();
Initialize the App Services App client and authenticate a user.
String appId = "<Atlas App ID>";
final appConfig = AppConfiguration(appId);
final app = App(appConfig);
final user = await app.logIn(Credentials.anonymous());
Open a synced realm.
final config = Configuration.flexibleSync(user, [Task.schema]);
final realm = Realm(config);
Add a sync subscription and write data.
Only data matching the query in the subscription will be synced to the server and only data matching the subscription will be downloaded to the local device realm file.
realm.subscriptions.update((mutableSubscriptions) {
mutableSubscriptions.add(realm.query<Task>(r'status == $0 AND progressMinutes == $1', ["completed", 100]));
});
await realm.subscriptions.waitForSynchronization();
realm.write(() {
realm.add(Task(ObjectId(), "Send an email", "completed", 4));
realm.add(Task(ObjectId(), "Create a meeting", "completed", 100));
realm.add(Task(ObjectId(), "Call the manager", "init", 2));
});
realm.close();
See CONTRIBUTING.md for instructions about building the source.
Code of Conduct
This project adheres to the MongoDB Code of Conduct.
By participating, you are expected to uphold this code. Please report
unacceptable behavior to [community-conduct@mongodb.com](mailto:community-conduct@mongodb.com).
License
Realm Flutter and Dart SDKs and Realm Core are published under the Apache License 2.0.
The "Dart" name and logo and the "Flutter" name and logo are trademarks owned by Google.