aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: f48fd88a0e3c0c6d820cf29e0a041ac181782e3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Fixgen - Language agnostic fixture generator

Usually wiring up fake test data is a bunch of work, especially when that data is relational. Fixgen helps to alleviate some of that pain by allowing you to very easily generate fixtures that can also reference other fixtures. It also has some nice characteristics:

- Single binary without dependencies
- Language agnostic
- Simple syntax
- Supports relations
- Written in OCaml

## Install

Check out the latest [release binary](https://codeberg.org/marcc/fixgen/releases), which contains install instructions.

## Usage

Fixgen makes it simple to generate fixtures. It comes with a tiny DSL:

```sh
$ fixgen 'user (2): id uuidv4, name name; purchase (10): id uuidv4, buyer user.id, amount int(1,40), currency ("USD","MXN")' -o fixtures
```

This will generate two files:

- 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

```
COPY users FROM '/fixtures/user.csv' CSV HEADER;
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.

### Supported types

Fixgen comes with the following built-in types:

- name

```sh
$ fixgen 'user (1): id name'
id
John
```

- uuidv4

```sh
$ fixgen '_(1): id uuiv4'
id
6ebe54f5-24b3-43ae-a9e4-f91c481755e
```

- int(min,max)

```sh
$ fixgen '_(2): number int(2,40)'
number
2
37
```

- constants

```sh
$ fixgen '_(2): name "Bob"'
name
Bob
Bob
```

- Union

```sh
$ fixgen '_(4): currency ("SEK","MXN","USD")'
currency
SEK
USD
MXN
MXN
```

- email

```sh
$ fixgen '_(1): email email'
email
judy@gmail.com
```

- increment

```sh
$ fixgen '_(4): id increment'
id
1
2
3
4
```

- Username

```sh
$ fixgen '_(4): user username'
user
ivan0
judy1
frank2
walter3
```

## Development - Prerequisites

- [Nix](https://nixos.org/manual/nix/stable/installation/installing-binary)
- [Direnv](https://direnv.net/docs/installation.html)

After installation, you will need to run direnv allow

```
direnv allow
```

And it will set up the development environment for you with the correct git hooks.

### VSCode

You'll need OCaml platform and direnv extension. Once you have those, you will need to start the project from the terminal. First, ensure you have setup code terminal command:

https://code.visualstudio.com/docs/setup/mac

Once in place, cd to the project and run

```
code .
```

And VSCode should launch correctly with LSP installed.

### Running development

```
./scripts/run-watch.sh
```

Run tests

```
./scripts/run-test-watch.sh
```

You can also run them manually:

```
dune runtests
```

### Building

```
dune build
```

### Contributing

[Mailing list](https://lists.sr.ht/~marcc/fixgen).

Send your patches via [mail](mailto:~marcc/fixgen@lists.sr.ht). New to mailing patches? Check out this [tutorial](https://git-send-email.io/).