-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* entity type analyzer: wip * misc * wip * little baby steps, we making progress 🔥 * use new orm structure * tiny fix * wip * use new improvements from orm * all tests passing * tiny fix * tiny fix * remove test code * restore db config switching
- Loading branch information
Showing
29 changed files
with
265 additions
and
199 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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{ | ||
"dart.lineLength": 120 | ||
} | ||
"dart.lineLength": 120, | ||
"[dart]": { | ||
"editor.rulers": [ | ||
120 | ||
], | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
// ignore: depend_on_referenced_packages | ||
import 'package:yaroo_cli/orm/orm.dart'; | ||
import 'package:backend/src/models/article/article.dart'; | ||
import 'package:backend/src/models/user/user.dart'; | ||
import 'package:yaroo_cli/orm.dart'; | ||
import 'package:yaroorm/yaroorm.dart'; | ||
|
||
import '../../database/config.dart' as orm; | ||
import 'migrator.reflectable.dart'; | ||
|
||
export 'package:backend/src/models/models.dart'; | ||
|
||
void main(List<String> args) async { | ||
initializeReflectable(); | ||
Query.addTypeDef<User>(userTypeData); | ||
Query.addTypeDef<Article>(articleTypeData); | ||
|
||
await OrmCLIRunner.start(args, orm.config); | ||
} |
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
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 |
---|---|---|
@@ -1,28 +1,14 @@ | ||
import 'package:backend/src/models/models.dart'; | ||
import 'package:yaroorm/migration.dart'; | ||
import 'package:backend/src/models/article/article.dart'; | ||
import 'package:yaroorm/yaroorm.dart'; | ||
|
||
class CreateArticlesTable extends Migration { | ||
@override | ||
void up(List<Schema> schemas) { | ||
final articleSchema = Schema.create('articles', (table) { | ||
return table | ||
..id() | ||
..string('title') | ||
..string('description') | ||
..string('imageUrl', nullable: true) | ||
..integer('ownerId') | ||
..foreign<Article, User>( | ||
column: 'ownerId', | ||
onKey: (fkey) => fkey.actions(onDelete: ForeignKeyAction.cascade, onUpdate: ForeignKeyAction.cascade), | ||
) | ||
..timestamps(); | ||
}); | ||
|
||
schemas.add(articleSchema); | ||
schemas.add(ArticleSchema); | ||
} | ||
|
||
@override | ||
void down(List actions) { | ||
actions.add(Schema.dropIfExists('articles')); | ||
actions.add(Schema.dropIfExists(ArticleSchema)); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,22 +1,14 @@ | ||
import 'package:yaroorm/migration.dart'; | ||
import 'package:backend/src/models/user/user.dart'; | ||
import 'package:yaroorm/yaroorm.dart'; | ||
|
||
class CreateUsersTable extends Migration { | ||
@override | ||
void up(List schemas) { | ||
final userSchema = Schema.create('users', (table) { | ||
return table | ||
..id() | ||
..string('name') | ||
..string('email') | ||
..string('password') | ||
..timestamps(); | ||
}); | ||
|
||
schemas.add(userSchema); | ||
schemas.add(UserSchema); | ||
} | ||
|
||
@override | ||
void down(List schemas) { | ||
schemas.add(Schema.dropIfExists('users')); | ||
schemas.add(Schema.dropIfExists(UserSchema)); | ||
} | ||
} |
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
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
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
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
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,57 @@ | ||
import 'package:yaroorm/yaroorm.dart'; | ||
|
||
import '../user/user.dart'; | ||
|
||
part 'article.g.dart'; | ||
|
||
@Table('articles', converters: [dateTimeConverter, booleanConverter]) | ||
class Article extends Entity<Article> { | ||
@primaryKey | ||
final int id; | ||
|
||
final String title; | ||
final String description; | ||
|
||
final String? imageUrl; | ||
|
||
@reference(User, name: 'owner_id', onDelete: ForeignKeyAction.cascade) | ||
final int ownerId; | ||
|
||
@createdAtCol | ||
final DateTime createdAt; | ||
|
||
@updatedAtCol | ||
final DateTime updatedAt; | ||
|
||
Article( | ||
this.id, | ||
this.title, | ||
this.ownerId, | ||
this.description, { | ||
this.imageUrl, | ||
required this.createdAt, | ||
required this.updatedAt, | ||
}); | ||
|
||
BelongsTo<Article, User> get owner => belongsTo<User>(); | ||
|
||
Map<String, dynamic> toJson() => <String, dynamic>{ | ||
'id': id, | ||
'createdAt': createdAt.toIso8601String(), | ||
'updatedAt': updatedAt.toIso8601String(), | ||
'title': title, | ||
'description': description, | ||
'imageUrl': imageUrl, | ||
'ownerId': ownerId, | ||
}; | ||
|
||
factory Article.fromJson(Map<String, dynamic> json) => Article( | ||
json['id'] as int, | ||
json['title'] as String, | ||
json['ownerId'] as int, | ||
json['description'] as String, | ||
imageUrl: json['imageUrl'] as String?, | ||
createdAt: DateTime.parse(json['createdAt'] as String), | ||
updatedAt: DateTime.parse(json['updatedAt'] as String), | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.