TableModel class
Represents a database table for Dart code generation.
This class models a PostgreSQL table and provides utilities for generating the corresponding Dart class code. It handles table structure analysis, property mapping, and code generation for database-to-Dart object conversion.
Example
For a PostgreSQL table like:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(255),
created_at TIMESTAMP DEFAULT NOW()
);
A TableModel would generate Dart code like:
class User {
User({
required this.id,
required this.name,
this.email,
this.createdAt,
});
final int id;
final String name;
final String? email;
final String? createdAt;
factory User.fromJson(Map<String, dynamic> json) {
return User(
id: json['id'],
name: json['name'],
email: json['email'],
createdAt: json['created_at'],
);
}
}
Constructors
-
TableModel.new({required String name, required List<
TableProperty> properties}) - Creates a new TableModel instance.
Properties
- className → String
-
The generated Dart class name in PascalCase.
no setter
- fromJsonFunction → String
-
Generates the
fromJson
factory constructor code.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- hasValidName → bool
-
Whether the table name can be converted to a valid Dart class name.
no setter
- name → String
-
The original database table name (e.g., 'user_profiles').
final
-
properties
→ List<
TableProperty> -
The list of table columns/properties.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createClass(
) → String - Generates the complete Dart class code.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited