aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Coquand <marc@mccd.space>2023-12-26 11:21:59 -0600
committerMarc Coquand <marc@mccd.space>2023-12-26 11:21:59 -0600
commit0dcc905f2fdc89f3be834c670a5bcf42386eb663 (patch)
tree71d960afcb27ffaf3c00994593acb98fbb206c4e
parentb826340d7536c2777fdcafb3bfcc6ebc8d8053ee (diff)
downloadfixgen-0dcc905f2fdc89f3be834c670a5bcf42386eb663.tar.gz
fixgen-0dcc905f2fdc89f3be834c670a5bcf42386eb663.tar.bz2
fixgen-0dcc905f2fdc89f3be834c670a5bcf42386eb663.zip
Update docs
Diffstat (limited to '')
-rw-r--r--README.md28
-rw-r--r--lib/ast_types.ml5
-rw-r--r--lib/fixture.ml2
3 files changed, 17 insertions, 18 deletions
diff --git a/README.md b/README.md
index e41f406..0e3b6ae 100644
--- a/README.md
+++ b/README.md
@@ -6,30 +6,20 @@ Usually wiring up fake test data is a bunch of work, especially when that data i
- Language agnostic
- Dead simple and fast grammar to generate fixtures in minutes
- Supports relations
-- Writing in OCaml
+- Written in OCaml
## Usage
-Simply define a fixgen file, for example sample.fixgen
-
-```
-user (2): id uuidv4, name name, email email
-purchase (10): id uuidv4, buyer user.id, amount int(1,40)
-```
-
-And then run it
+Fixgen makes it simple to generate fixtures. It comes with a tiny DSL:
```sh
-$ fixgen sample.fixgen -f csv -o fixtures
+$ fixgen 'user (2): id uuidv4, name name; purchase (10): id uuidv4, buyer user.id, amount int<1,40>, currency: ("USD","MXN")' -o fixtures
```
-Or just generate in-line:
+This will generate two files:
-```sh
-$ fixgen "user (2): id uuidv4, name name; purchase (10): id uuidv4, buyer user.id, amount int<1,40>
-```
-
-For it to generate two files with fake relational data: fixtures/purchase.csv, fixtures/user.csv. Bam! Simple as that.
+- fixtures/user.csv, will have two rows containing id and name
+- fixtures/purchase.csv, will have ten rows containing id, buyer (which will reference ids from user!), amount, currency.
You can then import it into your SQL server with simple copy from commands
@@ -40,6 +30,12 @@ COPY purchases FROM '/fixtures/purchase.csv' CSV HEADER;
Or maybe export as JSON instead to import into your NoSQL DB.
+```sh
+$ fixgen 'user (2): id uuidv4, name name; purchase (3): id uuidv4, buyer user.id, amount int<1,40>, currency: ("USD","MXN")' -f json
+```
+
+This will print two JSON arrays to stdout.
+
## Development - Prerequisites
- [Nix](https://nixos.org/manual/nix/stable/installation/installing-binary)
diff --git a/lib/ast_types.ml b/lib/ast_types.ml
index 7638d3b..6996435 100644
--- a/lib/ast_types.ml
+++ b/lib/ast_types.ml
@@ -13,11 +13,12 @@ type ast_row =
[@@deriving show, eq]
type ast_table =
+(** In hindsight, this could've been represented as a list of tables instead using separated list command
+
+ TODO: Rewrite this to use a list of tables instead of a tree *)
| Table of string * int * ast_row * ast_table
| End
[@@deriving show, eq]
-(** In hindsight, this could've been represented as a list of tables instead using separated list command
- TODO: Rewrite this to use a list of tables instead of a tree *)
let rec print_row = function
| Uuidv4 (s, r) ->
diff --git a/lib/fixture.ml b/lib/fixture.ml
index d28d4b3..94c39a9 100644
--- a/lib/fixture.ml
+++ b/lib/fixture.ml
@@ -135,6 +135,8 @@ let json_of_generated_fixtures fixtures =
"[" ^ String.concat ", " (List.map json_of_row rows) ^ "]"
+(* TODO: Should export not only as strings *)
+
let%test "json_of_generated_fixtures" =
let result = [ [ "id"; "name" ]; [ "1234"; "John" ] ] |> json_of_generated_fixtures in
result = "[{\"id\": \"1234\", \"name\": \"John\"}]"