Let's say I have a string like const fql = "CreateCollection({ name: "users" })"
. How do I turn it into a faunadb Expr
in JS?
You landed on the correct answer yourself. FQL is not a string-based language. This approach avoids problems like SQL injection, but it does mean you need to compose queries somewhere using a driver, the console, or a tool like Fauna Schema Migrate (FSM).
const fql = "CreateCollection({ name: "users" })"
The example you give leans toward schema/resource management. If that's your actual need here, consider FSM or the Fauna Serverless Framework plugin.
If you're building a front-end app using JavaScript, FSM is probably the right approach as it drops right into your app. It might also give you some more hints at how to transform strings into FQL. You would do the above in a single FQL file, e.g., fauna/resources/collections/users.fql
as:
CreateCollection({ name: "users" })
If you're doing infrastructure as code in a separate pipeline or are already building with the Serverless Framework, the plugin might be a better fit.
If you want to see something else like a Pulumi or Terraform provider plugins, please submit a feature request in the forums!