How to setup Spawn in existing projects
You've probably already got a project set up to use a database in your development environment. It might be a database engine installed and running locally, a shared instance in your network, or a dedicated instance via something like Docker or a VM.
It's easy to replace those instances with a Spawn data container. In this page, you'll learn how.
#
Programmatically pulling out connection detailsThe key is to get the Spawn data container connection details and supply that to your application. This is easy by using the -o json
flag on the spawnctl get data-container
command.
- MacOS/Linux
- Windows
As a human, this isn't much use. Thankfully, jq
is an excellent way to parse this output and pull out the useful parts as part of a script.
Already, we can see that jq
has pretty-printed the json for us. But we can even pull out the individual components now:
As you can see, it's very easy to pull out the individual parts. We can use this to construct environment variables or flags that we can supply to our applications.
As a human, this isn't much use. Thankfully, ConvertFrom-Json
is an excellent way to parse this output and pull out the useful parts as part of a script.
Already, we can see that ConvertFrom-Json
has pretty-printed the json for us. But we can even pull out the individual components now:
As you can see, it's very easy to pull out the individual parts. We can use this to construct environment variables or flags that we can supply to our applications.
Depending on your development approach, setting this environment variable once for the session may be enough. On the other hand, it might make sense to create a wrapper script for launching your application that runs these spawnctl
commands to construct the connection string on startup. If you've got other task runners that are part of your development process, then running spawnctl
commands as part of that process should be straightforward.
See this in action
To see an example of this working in a repository you can try, check out https://github.com/red-gate/spawn-demo
Still not sure how to get Spawn up and running in development? Something missing from this documentation? Let us know by joining our Slack or emailing spawn@red-gate.com and we'll work with you to get you up and running.