Cozy Data는 Swift의 데이터 관리 방식에서 영감을 받은 Flutter 패키지로, SQL을 사용하여 앱 모델을 타입 안전하고 직관적으로 지속적으로 저장할 수 있는 방법을 제공합니다. 데이터가 변경될 때 자동으로 UI 업데이트를 트리거하고 데이터베이스 작업을 자동으로 처리하여 반복 코드를 줄이고 개발 속도를 향상시킵니다. 간단함과 신뢰성에 중점을 두어 Flutter의 반응형 프레임워크와 원활하게 통합되며, 실시간 UI 동기화가 필요한 지속적 저장 기능을 필요로 하는 앱에 적합합니다.
A Swift-inspired persistent data management solution for Flutter. CozyData provides a simple, powerful, and type-safe way to persist your app's models and automatically update your UI when data changes.
final recipe = awaitCozyData.fetcById<Recipe>(persistentModelID: id);
Advanced Usage
The CozyQueryBuilder is a class used to construct complex SQL-like queries in a structured and programmatic way. It allows you to specify various components of a query, such as fields to group by, order by, having clauses, joins, limits, offsets, selected fields, subqueries, table aliases, and where conditions.
final customBuilder = CozyQueryBuilder(
// groupByFields: A list of fields by which the results should be grouped. In this case, it's an empty list, meaning no grouping is applied.
groupByFields: [],
// orderByFields: A list of fields by which the results should be ordered. It's also an empty list here, so no specific ordering is applied.
orderByFields: [],
// Conditions that filter the groups created by the groupBy clause. It's empty, indicating no such conditions.
havingClauses: [],
// joins: A list of join operations to combine rows from two or more tables based on a related column. No joins are specified here
joins: [],
// limit: The maximum number of records to return. Here, it's set to 10.
limit: 10,
// offset: The number of records to skip before starting to return records. It's set to 0, meaning no records are skipped.
offset: 0,
// selectFields: A list of fields to be selected in the query. It's empty, meaning all fields are selected
selectFields: [],
// subqueries: A list of subqueries to be included in the main query. It's empty, indicating no subqueries.
subqueries: [],
// tableAliases: A map of table aliases to be used in the query. It's an empty map here.
tableAliases: {},
// whereGroups: A list of conditions to filter the results. It's empty, meaning no filtering conditions are applied.
whereGroups: [],
);
Sorting and Filtering once
final recipes = awaitCozyData.fetch<Recipe>(customBuilder: customBuilder);
The CozyQueryController manages query operations for a CozyQueryListener. It allows adding where conditions, joins, order by fields, and custom queries to the listener.