Updated models

This commit is contained in:
thomashii@dukefirehawk.com 2023-01-02 09:01:11 +08:00
parent 7809c72f03
commit 86538f7af1
4 changed files with 36 additions and 8 deletions

View file

@ -1,5 +1,11 @@
# Change Log # Change Log
## 7.1.0
* Return -1 instead of throwing exception when id is null
* Added `idAsString` to return id or "" if null
* Added `AuditableModel`
## 7.0.0 ## 7.0.0
* Require Dart >= 2.17 * Require Dart >= 2.17

View file

@ -1,14 +1,19 @@
# Angel3 Basic Data Model # Angel3 Data Model
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_model?include_prereleases) ![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_model?include_prereleases)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) [![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/model/LICENSE) [![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/model/LICENSE)
Angel3 basic data model class, no longer with the added weight of the whole framework. The basic data models for Angel3 framework.
```dart ```dart
import 'package:angel3_model/angel3_model.dart'; import 'package:angel3_model/angel3_model.dart';
``` ```
This package was created to prevent dependency collisions with third-party packages. The available data models are:
* `Model` class
* A basic data model
* `AuditableModel` class
* A basic data model with audit log feature

View file

@ -1,6 +1,4 @@
//library angel3_model; /// Represents a generic data model with an ID and timestamps.
/// Represents arbitrary data, with an associated ID and timestamps.
class Model { class Model {
/// A unique identifier corresponding to this item. /// A unique identifier corresponding to this item.
String? id; String? id;
@ -14,5 +12,24 @@ class Model {
Model({this.id, this.createdAt, this.updatedAt}); Model({this.id, this.createdAt, this.updatedAt});
/// Returns the [id], parsed as an [int]. /// Returns the [id], parsed as an [int].
int get idAsInt => id != null ? int.tryParse(id!) ?? -1 : -1; int get idAsInt => id != null ? int.tryParse(id ?? "-1") ?? -1 : -1;
/// Returns the [id] or "" if null.
String get idAsString => id ?? "";
}
/// Represents a generic data model with audit log feature.
class AuditableModel extends Model {
/// The authorized user who created the record.
String? createdBy;
/// The user who updated the record last time.
String? updatedBy;
AuditableModel(
{super.id,
super.createdAt,
this.createdBy,
super.updatedAt,
this.updatedBy});
} }

View file

@ -1,5 +1,5 @@
name: angel3_model name: angel3_model
version: 7.0.0 version: 7.1.0
description: Angel3 basic data model class, no longer with the added weight of the whole framework. description: Angel3 basic data model class, no longer with the added weight of the whole framework.
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/model repository: https://github.com/dukefirehawk/angel/tree/master/packages/model