├── .gitignore
├── .vscode
└── launch.json
├── CHANGELOG.md
├── CONTRIBUTING.md
├── Cargo.lock
├── Cargo.toml
├── LICENSE.md
├── README.md
├── clippy.toml
├── surreal-codegen
├── Cargo.toml
├── cli.js
├── npm
│ ├── index.js
│ ├── install.js
│ └── package.json
└── src
│ └── main.rs
└── surreal_type_generator
├── Cargo.toml
├── src
├── lib.rs
├── step_1_parse_sql
│ ├── global_parameters.rs
│ ├── mod.rs
│ ├── query.rs
│ └── schema.rs
├── step_2_interpret
│ ├── function.rs
│ ├── mod.rs
│ ├── object.rs
│ ├── return_types.rs
│ ├── schema
│ │ └── mod.rs
│ ├── statements
│ │ ├── create_statement.rs
│ │ ├── delete_statement.rs
│ │ ├── insert_statement.rs
│ │ ├── let_statement.rs
│ │ ├── mod.rs
│ │ ├── return_statement.rs
│ │ ├── select_statement.rs
│ │ ├── update_statement.rs
│ │ └── upsert_statement.rs
│ └── utils.rs
├── step_3_codegen
│ ├── mod.rs
│ └── typescript
│ │ └── mod.rs
└── utils
│ ├── mod.rs
│ └── printing.rs
└── tests
├── casting_javascript.rs
├── complex_query.rs
├── constant_expression_tests.rs
├── create_statement_tests.rs
├── delete_statement_tests.rs
├── field_defaults.rs
├── functions.rs
├── insert_statement_tests.rs
├── let_statement_tests.rs
├── literals_tests.rs
├── object.rs
├── precomputed_views.rs
├── return_and_expressions.rs
├── schema_complex_types.rs
├── select_grouping.rs
├── select_statement_tests.rs
├── subquery_tests.rs
├── transaction.rs
├── typescript_generation.rs
├── update_statement_tests.rs
├── upsert_statement_tests.rs
└── variable_usage_tests.rs
/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 | dist
3 | builds
4 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "lldb",
9 | "request": "launch",
10 | "name": "Debug executable 'surreal-codegen'",
11 | "cargo": {
12 | "args": [
13 | "build",
14 | "--bin=surreal-codegen",
15 | "--package=surreal-codegen"
16 | ],
17 | "filter": {
18 | "name": "surreal-codegen",
19 | "kind": "bin"
20 | }
21 | },
22 | "args": [],
23 | "cwd": "${workspaceFolder}"
24 | },
25 | {
26 | "type": "lldb",
27 | "request": "launch",
28 | "name": "Debug unit tests in executable 'surreal-codegen'",
29 | "cargo": {
30 | "args": [
31 | "test",
32 | "--no-run",
33 | "--bin=surreal-codegen",
34 | "--package=surreal-codegen"
35 | ],
36 | "filter": {
37 | "name": "surreal-codegen",
38 | "kind": "bin"
39 | }
40 | },
41 | "args": [],
42 | "cwd": "${workspaceFolder}"
43 | },
44 | {
45 | "type": "lldb",
46 | "request": "launch",
47 | "name": "Debug unit tests in library 'surreal_type_generator'",
48 | "cargo": {
49 | "args": [
50 | "test",
51 | "--no-run",
52 | "--lib",
53 | "--package=surreal_type_generator"
54 | ],
55 | "filter": {
56 | "name": "surreal_type_generator",
57 | "kind": "lib"
58 | }
59 | },
60 | "args": [],
61 | "cwd": "${workspaceFolder}"
62 | },
63 | {
64 | "type": "lldb",
65 | "request": "launch",
66 | "name": "Debug integration test 'return_and_expressions'",
67 | "cargo": {
68 | "args": [
69 | "test",
70 | "--no-run",
71 | "--test=return_and_expressions",
72 | "--package=surreal_type_generator"
73 | ],
74 | "filter": {
75 | "name": "return_and_expressions",
76 | "kind": "test"
77 | }
78 | },
79 | "args": [],
80 | "cwd": "${workspaceFolder}"
81 | },
82 | {
83 | "type": "lldb",
84 | "request": "launch",
85 | "name": "Debug integration test 'subquery_tests'",
86 | "cargo": {
87 | "args": [
88 | "test",
89 | "--no-run",
90 | "--test=subquery_tests",
91 | "--package=surreal_type_generator"
92 | ],
93 | "filter": {
94 | "name": "subquery_tests",
95 | "kind": "test"
96 | }
97 | },
98 | "args": [],
99 | "cwd": "${workspaceFolder}"
100 | },
101 | {
102 | "type": "lldb",
103 | "request": "launch",
104 | "name": "Debug integration test 'object'",
105 | "cargo": {
106 | "args": [
107 | "test",
108 | "--no-run",
109 | "--test=object",
110 | "--package=surreal_type_generator"
111 | ],
112 | "filter": {
113 | "name": "object",
114 | "kind": "test"
115 | }
116 | },
117 | "args": [],
118 | "cwd": "${workspaceFolder}"
119 | },
120 | {
121 | "type": "lldb",
122 | "request": "launch",
123 | "name": "Debug integration test 'casting_javascript'",
124 | "cargo": {
125 | "args": [
126 | "test",
127 | "--no-run",
128 | "--test=casting_javascript",
129 | "--package=surreal_type_generator"
130 | ],
131 | "filter": {
132 | "name": "casting_javascript",
133 | "kind": "test"
134 | }
135 | },
136 | "args": [],
137 | "cwd": "${workspaceFolder}"
138 | },
139 | {
140 | "type": "lldb",
141 | "request": "launch",
142 | "name": "Debug integration test 'update_statement_tests'",
143 | "cargo": {
144 | "args": [
145 | "test",
146 | "--no-run",
147 | "--test=update_statement_tests",
148 | "--package=surreal_type_generator"
149 | ],
150 | "filter": {
151 | "name": "update_statement_tests",
152 | "kind": "test"
153 | }
154 | },
155 | "args": [],
156 | "cwd": "${workspaceFolder}"
157 | },
158 | {
159 | "type": "lldb",
160 | "request": "launch",
161 | "name": "Debug integration test 'insert_statement_tests'",
162 | "cargo": {
163 | "args": [
164 | "test",
165 | "--no-run",
166 | "--test=insert_statement_tests",
167 | "--package=surreal_type_generator"
168 | ],
169 | "filter": {
170 | "name": "insert_statement_tests",
171 | "kind": "test"
172 | }
173 | },
174 | "args": [],
175 | "cwd": "${workspaceFolder}"
176 | },
177 | {
178 | "type": "lldb",
179 | "request": "launch",
180 | "name": "Debug integration test 'functions'",
181 | "cargo": {
182 | "args": [
183 | "test",
184 | "--no-run",
185 | "--test=functions",
186 | "--package=surreal_type_generator"
187 | ],
188 | "filter": {
189 | "name": "functions",
190 | "kind": "test"
191 | }
192 | },
193 | "args": [],
194 | "cwd": "${workspaceFolder}"
195 | },
196 | {
197 | "type": "lldb",
198 | "request": "launch",
199 | "name": "Debug integration test 'precomputed_views'",
200 | "cargo": {
201 | "args": [
202 | "test",
203 | "--no-run",
204 | "--test=precomputed_views",
205 | "--package=surreal_type_generator"
206 | ],
207 | "filter": {
208 | "name": "precomputed_views",
209 | "kind": "test"
210 | }
211 | },
212 | "args": [],
213 | "cwd": "${workspaceFolder}"
214 | },
215 | {
216 | "type": "lldb",
217 | "request": "launch",
218 | "name": "Debug integration test 'variable_usage_tests'",
219 | "cargo": {
220 | "args": [
221 | "test",
222 | "--no-run",
223 | "--test=variable_usage_tests",
224 | "--package=surreal_type_generator"
225 | ],
226 | "filter": {
227 | "name": "variable_usage_tests",
228 | "kind": "test"
229 | }
230 | },
231 | "args": [],
232 | "cwd": "${workspaceFolder}"
233 | },
234 | {
235 | "type": "lldb",
236 | "request": "launch",
237 | "name": "Debug integration test 'constant_expression_tests'",
238 | "cargo": {
239 | "args": [
240 | "test",
241 | "--no-run",
242 | "--test=constant_expression_tests",
243 | "--package=surreal_type_generator"
244 | ],
245 | "filter": {
246 | "name": "constant_expression_tests",
247 | "kind": "test"
248 | }
249 | },
250 | "args": [],
251 | "cwd": "${workspaceFolder}"
252 | },
253 | {
254 | "type": "lldb",
255 | "request": "launch",
256 | "name": "Debug integration test 'select_grouping'",
257 | "cargo": {
258 | "args": [
259 | "test",
260 | "--no-run",
261 | "--test=select_grouping",
262 | "--package=surreal_type_generator"
263 | ],
264 | "filter": {
265 | "name": "select_grouping",
266 | "kind": "test"
267 | }
268 | },
269 | "args": [],
270 | "cwd": "${workspaceFolder}"
271 | },
272 | {
273 | "type": "lldb",
274 | "request": "launch",
275 | "name": "Debug integration test 'select_statements_tests'",
276 | "cargo": {
277 | "args": [
278 | "test",
279 | "--no-run",
280 | "--test=select_statements_tests",
281 | "--package=surreal_type_generator"
282 | ],
283 | "filter": {
284 | "name": "select_statements_tests",
285 | "kind": "test"
286 | }
287 | },
288 | "args": [],
289 | "cwd": "${workspaceFolder}"
290 | },
291 | {
292 | "type": "lldb",
293 | "request": "launch",
294 | "name": "Debug integration test 'typescript_generation'",
295 | "cargo": {
296 | "args": [
297 | "test",
298 | "--no-run",
299 | "--test=typescript_generation",
300 | "--package=surreal_type_generator"
301 | ],
302 | "filter": {
303 | "name": "typescript_generation",
304 | "kind": "test"
305 | }
306 | },
307 | "args": [],
308 | "cwd": "${workspaceFolder}"
309 | },
310 | {
311 | "type": "lldb",
312 | "request": "launch",
313 | "name": "Debug integration test 'create_statement_tests'",
314 | "cargo": {
315 | "args": [
316 | "test",
317 | "--no-run",
318 | "--test=create_statement_tests",
319 | "--package=surreal_type_generator"
320 | ],
321 | "filter": {
322 | "name": "create_statement_tests",
323 | "kind": "test"
324 | }
325 | },
326 | "args": [],
327 | "cwd": "${workspaceFolder}"
328 | },
329 | {
330 | "type": "lldb",
331 | "request": "launch",
332 | "name": "Debug integration test 'delete_statement_tests'",
333 | "cargo": {
334 | "args": [
335 | "test",
336 | "--no-run",
337 | "--test=delete_statement_tests",
338 | "--package=surreal_type_generator"
339 | ],
340 | "filter": {
341 | "name": "delete_statement_tests",
342 | "kind": "test"
343 | }
344 | },
345 | "args": [],
346 | "cwd": "${workspaceFolder}"
347 | }
348 | ]
349 | }
350 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 | # Changelog
3 |
4 | ## v0.1.0
5 | - Initial release
6 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 |
2 | # Contributing
3 |
4 | 1. Clone the git repository
5 | - `git clone https://github.com/siteforge-io/surreal-codegen.git`
6 | 2. Run `cargo test` to run the tests - and this will build the project
7 | 3. Before you start writing code, ideally first open an issue with a minimum reproducible example of the bug or feature you want to add
8 | 3. Using the minimum reproduction, first write a failing test.
9 | 4. Write the code to fix/solve the issue.
10 | 5. Run the tests, and ensure they all pass.
11 | 6. In a fork, perform a git commit, with a message that includes the `Closes #issue_number`
12 | 7. Submit a pull request
13 | 8. Wait for the pull request to be reviewed and merged
14 |
15 |
16 | ## Releasing (for maintainers)
17 |
18 | 1. Push a git commit into main
19 | 2. To install, run `cargo install --git https://github.com/siteforge-io/surreal-codegen.git`
20 |
21 | ## Local Installation
22 |
23 | 1. Clone the git repository
24 | - `git clone https://github.com/siteforge-io/surreal-codegen.git`
25 | 2. Run `cargo install --path surreal-codegen`
26 | 3. Run `surreal-codegen --help` to see the available commands
27 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [workspace]
2 | resolver = "2"
3 |
4 | members = ["surreal-codegen", "surreal_type_generator"]
5 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Albert Marashi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # `surreal-codegen`
2 | > [!WARNING]
3 | > This is a WIP, but we are currently using it in production at [Siteforge](https://siteforge.io) to help ensure type safety in our SurrealDB queries.
4 | > See the [Features Supported](#features-supported) section for a list of features we currently support.
5 |
6 | # Installation
7 | > [!WARNING]
8 | > We haven't currently setup a build automation system, so you must build via the manual installation instructions below.
9 |
10 |
11 | ## Manual Installation
12 | You must have the rust toolchain installed, then run:
13 |
14 | ```sh
15 | cargo install --git https://github.com/siteforge-io/surreal-codegen.git
16 | ```
17 | Or, if you have cloned the repo:
18 | ```sh
19 | cargo install --path surreal-codegen
20 | ```
21 |
22 | ## Running `surreal-codegen`
23 | ```sh
24 | surreal-codegen --help
25 | ```
26 |
27 | ```
28 | Usage: surreal-codegen [OPTIONS] --dir
--schema
29 |
30 | Options:
31 | -d, --dir The directory containing the Surql files
32 | -s, --schema
33 | -o, --output