Last active
October 10, 2022 18:26
-
-
Save fischerscode/633c87f14ac79ecd4e01e656c7496f38 to your computer and use it in GitHub Desktop.
Serverpod generated example class.
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
// ignore_for_file: no_leading_underscores_for_library_prefixes | |
import 'package:serverpod/serverpod.dart' as _i1; | |
import 'package:serverpod/protocol.dart' as _i2; | |
import 'package:serverpod_auth_server/module.dart' as _i3; | |
import 'package:serverpod_serialization/serverpod_serialization.dart' as _i4; | |
class Example extends _i1.TableRow { | |
Example({ | |
this.id, | |
required this.name, | |
required this.data, | |
required this.cache, | |
required this.info, | |
}); | |
static final t = ExampleTable(); | |
@override | |
late int? id; | |
String name; | |
int data; | |
_i2.CacheInfo cache; | |
_i3.AppleAuthInfo info; | |
@override | |
String get className => 'Example'; | |
@override | |
String get tableName => 'example'; | |
static Example fromJson( | |
Map<String, dynamic> jsonSerialization, | |
_i4.SerializationManager serializationManager, | |
) { | |
return Example( | |
id: serializationManager.deserializeJson<int?>(jsonSerialization['id']), | |
name: serializationManager | |
.deserializeJson<String>(jsonSerialization['name']), | |
data: | |
serializationManager.deserializeJson<int>(jsonSerialization['data']), | |
cache: serializationManager | |
.deserializeJson<_i2.CacheInfo>(jsonSerialization['cache']), | |
info: serializationManager | |
.deserializeJson<_i3.AppleAuthInfo>(jsonSerialization['info']), | |
); | |
} | |
@override | |
Map<String, dynamic> toJson() { | |
return { | |
'id': id, | |
'name': name, | |
'data': data, | |
'cache': cache, | |
'info': info, | |
}; | |
} | |
@override | |
Map<String, dynamic> toJsonForDatabase() { | |
return { | |
'id': id, | |
'name': name, | |
'data': data, | |
'cache': cache, | |
'info': info, | |
}; | |
} | |
@override | |
Map<String, dynamic> allToJson() { | |
return { | |
'id': id, | |
'name': name, | |
'data': data, | |
'cache': cache, | |
'info': info, | |
}; | |
} | |
@override | |
void setColumn( | |
String columnName, | |
value, | |
) { | |
switch (columnName) { | |
case 'id': | |
id = value; | |
return; | |
case 'name': | |
name = value; | |
return; | |
case 'data': | |
data = value; | |
return; | |
case 'cache': | |
cache = value; | |
return; | |
case 'info': | |
info = value; | |
return; | |
default: | |
throw UnimplementedError(); | |
} | |
} | |
static Future<List<Example>> find( | |
_i1.Session session, { | |
ExampleExpressionBuilder? where, | |
int? limit, | |
int? offset, | |
_i1.Column? orderBy, | |
List<_i1.Order>? orderByList, | |
bool orderDescending = false, | |
bool useCache = true, | |
_i1.Transaction? transaction, | |
}) async { | |
return session.db.find<Example>( | |
where: where != null ? where(Example.t) : null, | |
limit: limit, | |
offset: offset, | |
orderBy: orderBy, | |
orderByList: orderByList, | |
orderDescending: orderDescending, | |
useCache: useCache, | |
transaction: transaction, | |
); | |
} | |
static Future<Example?> findSingleRow( | |
_i1.Session session, { | |
ExampleExpressionBuilder? where, | |
int? offset, | |
_i1.Column? orderBy, | |
bool orderDescending = false, | |
bool useCache = true, | |
_i1.Transaction? transaction, | |
}) async { | |
return session.db.findSingleRow<Example>( | |
where: where != null ? where(Example.t) : null, | |
offset: offset, | |
orderBy: orderBy, | |
orderDescending: orderDescending, | |
useCache: useCache, | |
transaction: transaction, | |
); | |
} | |
static Future<Example?> findById( | |
_i1.Session session, | |
int id, | |
) async { | |
return session.db.findById<Example>(id); | |
} | |
static Future<int> delete( | |
_i1.Session session, { | |
required ExampleExpressionBuilder where, | |
_i1.Transaction? transaction, | |
}) async { | |
return session.db.delete<Example>( | |
where: where(Example.t), | |
transaction: transaction, | |
); | |
} | |
static Future<bool> deleteRow( | |
_i1.Session session, | |
Example row, { | |
_i1.Transaction? transaction, | |
}) async { | |
return session.db.deleteRow( | |
row, | |
transaction: transaction, | |
); | |
} | |
static Future<bool> update( | |
_i1.Session session, | |
Example row, { | |
_i1.Transaction? transaction, | |
}) async { | |
return session.db.update( | |
row, | |
transaction: transaction, | |
); | |
} | |
static Future<void> insert( | |
_i1.Session session, | |
Example row, { | |
_i1.Transaction? transaction, | |
}) async { | |
return session.db.insert( | |
row, | |
transaction: transaction, | |
); | |
} | |
static Future<int> count( | |
_i1.Session session, { | |
ExampleExpressionBuilder? where, | |
int? limit, | |
bool useCache = true, | |
_i1.Transaction? transaction, | |
}) async { | |
return session.db.count<Example>( | |
where: where != null ? where(Example.t) : null, | |
limit: limit, | |
useCache: useCache, | |
transaction: transaction, | |
); | |
} | |
} | |
typedef ExampleExpressionBuilder = _i1.Expression Function(ExampleTable); | |
class ExampleTable extends _i1.Table { | |
ExampleTable() : super(tableName: 'example'); | |
final id = _i1.ColumnInt('id'); | |
final name = _i1.ColumnString('name'); | |
final data = _i1.ColumnInt('data'); | |
final cache = _i1.ColumnSerializable('cache'); | |
final info = _i1.ColumnSerializable('info'); | |
@override | |
List<_i1.Column> get columns => [ | |
id, | |
name, | |
data, | |
cache, | |
info, | |
]; | |
} | |
@Deprecated('Use ExampleTable.t instead.') | |
ExampleTable tExample = ExampleTable(); |
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
// ignore_for_file: no_leading_underscores_for_library_prefixes | |
import 'package:serverpod_serialization/serverpod_serialization.dart' as _i1; | |
enum TestEnum with _i1.SerializableEntity { | |
test1, | |
test2, | |
test3; | |
@override | |
String get className => 'TestEnum'; | |
static TestEnum? fromJson(int index) { | |
switch (index) { | |
case 0: | |
return test1; | |
case 1: | |
return test2; | |
case 2: | |
return test3; | |
default: | |
return null; | |
} | |
} | |
int toJson() => index; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment