fdark 1.0.1 copy "fdark: ^1.0.1" to clipboard
fdark: ^1.0.1 copied to clipboard

outdated

Enhanced API server

example/fdark_example.dart

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 rows = await db.query('SELECT * FROM users WHERE email=@email', pars: {
    'email': 'iam.pangaribuan@gmail.com',
  });

  final users = 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,
    });
  }
}
1
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Enhanced API server

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

fdation, meta, postgres, shelf, shelf_router

More

Packages that depend on fdark