flood 0.1.4

Flood #

A data-generator for databases using Aqueduct.

Usage #

An example for a Hero model containing a name field. This function could then be called in for example, any Harness with the TestHarnessORMMixin.

import 'package:aqueduct_test/aqueduct_test.dart';
import 'package:faker/faker.dart';
import 'package:flood/flood.dart';

class ExampleHarness extends TestHarness<DbChannel> with TestHarnessORMMixin {
  @override
  ManagedContext get context => channel.context;

  @override
  Future seed() async {
    await initializeDb(context);
  }

  initializeDb(ManagedContext context) async {
    // An instance of GenerationScheme needs to be created for each model
    var heroScheme = GenerationScheme(
      // The ManagedEntity instance for the Hero model
      context.entityForType(Hero),
      
      // The generation method to use for the name field
      {"name": () => "hero_" + faker.internet.userName()},
      
      // Number of objects to create
      5,
    );
    var flood = Flood(context);
    // Register the GenerationScheme.
    flood.register(heroScheme);
    return await flood.fill();
  }
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.1.4 #

  • Cleaned up the example
  • Moved faker to the dev_dependencies

0.1.3 #

  • Fixed partial docs due to missing library exports.

0.1.2 #

  • Fixed structure to follow the pub recommendations.

0.1.1 #

  • Initial version.

example/main.dart

import 'dart:math';

import 'package:aqueduct_test/aqueduct_test.dart';
import 'package:faker/faker.dart';
import 'package:flood/flood.dart';

import 'lib/db.dart';

class ExampleHarness extends TestHarness<DbChannel> with TestHarnessORMMixin {
  @override
  ManagedContext get context => channel.context;

  @override
  Future seed() async {
    await initializeDb(context);
  }

  Future<Map<ManagedEntity, List<ManagedObject>>> initializeDb(
      ManagedContext context) async {
    Flood flood = Flood(context);
    Faker faker = Faker();
    GenerationScheme heroScheme = GenerationScheme(
      context.entityForType(Hero),
      {"name": () => "hero_" + faker.internet.userName()},
      5,
    );

    GenerationScheme villainScheme = GenerationScheme(
      context.entityForType(Villain),
      {"name": () => "villain_" + faker.internet.userName()},
      5,
    );

    GenerationScheme rivalryScheme = GenerationScheme(
      context.entityForType(Rivalry),
      {},
      10,
    );

    GenerationScheme battleScheme = GenerationScheme(
      context.entityForType(Battle),
      {"heroWon": Random().nextBool},
      20,
    );

    GenerationScheme fanScheme = GenerationScheme(
      context.entityForType(Fan),
      {"name": () => "fan_" + faker.internet.userName()},
      5,
    );

    flood.registerAll([
      heroScheme,
      villainScheme,
      rivalryScheme,
      battleScheme,
      fanScheme,
    ]);
    return flood.fill();
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flood: ^0.1.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flood/flood.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
94
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Jul 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: other

Primary library: package:flood/flood.dart with components: io, isolate, mirrors.

Health suggestions

Fix lib/src/dependancy_graph.dart. (-2.48 points)

Analysis of lib/src/dependancy_graph.dart reported 5 hints:

line 7 col 7: Don't type annotate initializing formals.

line 7 col 21: Don't type annotate initializing formals.

line 7 col 48: Don't type annotate initializing formals.

line 7 col 75: Use ; instead of {} for empty constructor bodies.

line 9 col 19: Don't type annotate initializing formals.

Fix lib/src/generation_scheme.dart. (-1.49 points)

Analysis of lib/src/generation_scheme.dart reported 3 hints:

line 20 col 5: Don't type annotate initializing formals.

line 21 col 5: Don't type annotate initializing formals.

line 22 col 5: Don't type annotate initializing formals.

Fix lib/src/flood.dart. (-1 points)

Analysis of lib/src/flood.dart reported 2 hints:

line 19 col 9: Don't type annotate initializing formals.

line 19 col 38: Use ; instead of {} for empty constructor bodies.

Fix lib/src/query_creator.dart. (-1 points)

Analysis of lib/src/query_creator.dart reported 2 hints:

line 19 col 7: DO use curly braces for all flow control structures.

line 21 col 7: DO use curly braces for all flow control structures.

Fix lib/flood.dart. (-0.50 points)

Analysis of lib/flood.dart reported 1 hint:

line 15 col 8: Unused import: 'src/test/model/model.dart'.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
aqueduct ^3.1.0+1 3.2.1
Transitive dependencies
analyzer 0.35.4 0.37.0
args 1.5.2
async 2.3.0
charcode 1.1.2
codable 1.0.0
collection 1.14.11
convert 2.1.1
crypto 2.0.6
front_end 0.1.14 0.1.20
glob 1.1.7
isolate_executor 2.0.2+3
kernel 0.3.14 0.3.20
logging 0.11.3+2
meta 1.1.7
open_api 2.0.1
package_config 1.0.5
password_hash 2.0.0
path 1.6.2
postgres 1.0.2 2.0.0-dev1.0
pub_cache 0.2.3
pub_semver 1.4.2
safe_config 2.0.2
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.1.16
Dev dependencies
aqueduct_test ^1.0.0
faker ^1.0.0
pedantic ^1.4.0 1.8.0+1
test ^1.0.0

Admin