fdark 1.0.4 fdark: ^1.0.4 copied to clipboard
Enhanced API server
import 'package:fdark/fdark.dart';
import 'package:fdation/fdation.dart';
final FDB db = FPostgresDB(
host: '127.0.0.1',
port: 5432,
name: 'fdark',
user: 'postgres',
password: 'postgres',
scheme: 'public',
settings: FConnectionSettings(
maxIdle: 2,
maxOpen: 10,
idleLifetime: Duration(minutes: 30),
openLifetime: Duration(minutes: 5),
),
);
void main() async {
final dbr = await db.select(
sql: 'SELECT * FROM users WHERE email=@email',
pars: {
'email': 'iam.pangaribuan@gmail.com',
},
);
if (dbr.err.isError) {
print(dbr.err.err);
} else {
final users = dbr.rows.loopToList((row) => User.fromRow(row));
for (final user in users) {
print(user.name);
}
}
}
class User extends FJsonSerializable {
int id;
String name;
String email;
int? idNumber;
bool isActive;
bool isFirstLogin;
DateTime createdAt;
User({
required this.id,
required this.name,
required this.email,
this.idNumber,
required this.isActive,
required this.isFirstLogin,
required this.createdAt,
});
factory User.fromRow(FDBRow row) {
return User(
id: row['id'],
name: row.get('name')!,
email: row['email'],
idNumber: row.get('id_number'),
isActive: row['is_active'],
isFirstLogin: row.get('firstLogin')!,
createdAt: row.get('created_at'),
);
}
@override
Map<String, dynamic> serialize() {
final keys = <String>[];
return omitempty(keys, {
'id': id,
'name': name,
'email': email,
'idNumber': idNumber,
'isActive': isActive,
'isFirstLogin': isFirstLogin,
'createdAt': createdAt,
});
}
}