import 'dart:async';
import 'package:jaguar_orm/jaguar_orm.dart';
import 'package:jaguar_serializer/jaguar_serializer.dart';
part 'pojo_brand.jorm.dart';
part 'pojo_brand.jser.dart';
class PojoBrand{
@PrimaryKey(auto: true, isNullable: false)
int id;
String name;
int status;
PojoBrand({this.id, this.name, this.status = 1});
static const String tableName = 'brand';
@override
bool operator ==(other) {
if(other is PojoBrand){
PojoBrand o = other as PojoBrand;
return this.id == o.id && this.name == o.name;
}
return false;
}
}
@GenSerializer()
class PojoBrandSerializer extends Serializer<PojoBrand>
with _$PojoBrandSerializer {}
@GenBean()
class PojoBrandBean extends Bean<PojoBrand> with _PojoBrandBean {
PojoBrandBean(Adapter adapter) : super(adapter);
String get tableName => 'brand';
}
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'pojo_brand.dart';
// **************************************************************************
// BeanGenerator
// **************************************************************************
abstract class _PojoBrandBean implements Bean<PojoBrand> {
final id = IntField('id');
final name = StrField('name');
final status = IntField('status');
Map<String, Field> _fields;
Map<String, Field> get fields => _fields ??= {
id.name: id,
name.name: name,
status.name: status,
};
PojoBrand fromMap(Map map) {
PojoBrand model = PojoBrand();
model.id = adapter.parseValue(map['id']);
model.name = adapter.parseValue(map['name']);
model.status = adapter.parseValue(map['status']);
return model;
}
List<SetColumn> toSetColumns(PojoBrand model,
{bool update = false, Set<String> only, bool onlyNonNull = false}) {
List<SetColumn> ret = [];
if (only == null && !onlyNonNull) {
if (model.id != null) {
ret.add(id.set(model.id));
}
ret.add(name.set(model.name));
ret.add(status.set(model.status));
} else if (only != null) {
if (model.id != null) {
if (only.contains(id.name)) ret.add(id.set(model.id));
}
if (only.contains(name.name)) ret.add(name.set(model.name));
if (only.contains(status.name)) ret.add(status.set(model.status));
} else /* if (onlyNonNull) */ {
if (model.id != null) {
ret.add(id.set(model.id));
}
if (model.name != null) {
ret.add(name.set(model.name));
}
if (model.status != null) {
ret.add(status.set(model.status));
}
}
return ret;
}
Future<void> createTable({bool ifNotExists = false}) async {
final st = Sql.create(tableName, ifNotExists: ifNotExists);
st.addInt(id.name, primary: true, autoIncrement: true, isNullable: false);
st.addStr(name.name, isNullable: false);
st.addInt(status.name, isNullable: false);
return adapter.createTable(st);
}
Future<dynamic> insert(PojoBrand model,
{bool cascade = false,
bool onlyNonNull = false,
Set<String> only}) async {
final Insert insert = inserter
.setMany(toSetColumns(model, only: only, onlyNonNull: onlyNonNull))
.id(id.name);
var retId = await adapter.insert(insert);
if (cascade) {
PojoBrand newModel;
}
return retId;
}
Future<void> insertMany(List<PojoBrand> models,
{bool onlyNonNull = false, Set<String> only}) async {
final List<List<SetColumn>> data = models
.map((model) =>
toSetColumns(model, only: only, onlyNonNull: onlyNonNull))
.toList();
final InsertMany insert = inserters.addAll(data);
await adapter.insertMany(insert);
return;
}
Future<dynamic> upsert(PojoBrand model,
{bool cascade = false,
Set<String> only,
bool onlyNonNull = false}) async {
final Upsert upsert = upserter
.setMany(toSetColumns(model, only: only, onlyNonNull: onlyNonNull))
.id(id.name);
var retId = await adapter.upsert(upsert);
if (cascade) {
PojoBrand newModel;
}
return retId;
}
Future<void> upsertMany(List<PojoBrand> models,
{bool onlyNonNull = false, Set<String> only}) async {
final List<List<SetColumn>> data = [];
for (var i = 0; i < models.length; ++i) {
var model = models[i];
data.add(
toSetColumns(model, only: only, onlyNonNull: onlyNonNull).toList());
}
final UpsertMany upsert = upserters.addAll(data);
await adapter.upsertMany(upsert);
return;
}
Future<int> update(PojoBrand model,
{bool cascade = false,
bool associate = false,
Set<String> only,
bool onlyNonNull = false}) async {
final Update update = updater
.where(this.id.eq(model.id))
.setMany(toSetColumns(model, only: only, onlyNonNull: onlyNonNull));
return adapter.update(update);
}
Future<void> updateMany(List<PojoBrand> models,
{bool onlyNonNull = false, Set<String> only}) async {
final List<List<SetColumn>> data = [];
final List<Expression> where = [];
for (var i = 0; i < models.length; ++i) {
var model = models[i];
data.add(
toSetColumns(model, only: only, onlyNonNull: onlyNonNull).toList());
where.add(this.id.eq(model.id));
}
final UpdateMany update = updaters.addAll(data, where);
await adapter.updateMany(update);
return;
}
Future<PojoBrand> find(int id,
{bool preload = false, bool cascade = false}) async {
final Find find = finder.where(this.id.eq(id));
return await findOne(find);
}
Future<int> remove(int id) async {
final Remove remove = remover.where(this.id.eq(id));
return adapter.remove(remove);
}
Future<int> removeMany(List<PojoBrand> models) async {
// Return if models is empty. If this is not done, all records will be removed!
if (models == null || models.isEmpty) return 0;
final Remove remove = remover;
for (final model in models) {
remove.or(this.id.eq(model.id));
}
return adapter.remove(remove);
}
}
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'pojo_brand.dart';
// **************************************************************************
// JaguarSerializerGenerator
// **************************************************************************
abstract class _$PojoBrandSerializer implements Serializer<PojoBrand> {
@override
Map<String, dynamic> toMap(PojoBrand model) {
if (model == null) return null;
Map<String, dynamic> ret = <String, dynamic>{};
setMapValue(ret, 'id', model.id);
setMapValue(ret, 'name', model.name);
setMapValue(ret, 'status', model.status);
return ret;
}
@override
PojoBrand fromMap(Map map) {
if (map == null) return null;
final obj = new PojoBrand();
obj.id = map['id'] as int;
obj.name = map['name'] as String;
obj.status = map['status'] as int;
return obj;
}
}
error: The name 'Field' is defined in the libraries 'package:jaguar_query/src/core/core.dart' and 'package:jaguar_serializer/src/annotations/annotations.dart'. (ambiguous_import at [firsttry] lib\model\pojo_brand.jorm.dart:13)
error: '_PojoBrandBean.fields' ('() → Map<String, dynamic>') isn't a valid override of 'Bean.fields' ('() → Map<String, Field>'). (invalid_override at [firsttry] lib\model\pojo_brand.dart:33)
}
error: The name 'Field' is defined in the libraries 'package:jaguar_query/src/core/core.dart' and 'package:jaguar_serializer/src/annotations/annotations.dart'. (ambiguous_import at [firsttry] lib\model\pojo_brand.jorm.dart:13)
error: '_PojoBrandBean.fields' ('() → Map<String, dynamic>') isn't a valid override of 'Bean.fields' ('() → Map<String, Field>'). (invalid_override at [firsttry] lib\model\pojo_brand.dart:33)