Replace the example name and email address in the following steps with the ones you used for your Github account. If you don't already have a Github account, make sure to register. We'll be using Git for our version control system so we're going to set it up to match our Github account. # Install yarn for Rails jsbundling/cssbundling or webpacker Then we can install the latest Node.js for handling Javascript in our Rails apps: asdf install nodejs 18.16.1 To install Ruby and set the default version, we'll run the following commands: asdf install ruby 3.2.2Ĭonfirm the default Ruby version matches the version you just installed. asdf plugin add rubyĬhoose the version of Ruby you want to install: For Rails, we can install Ruby and Node.js for our frontend Javascript. Then we can install ASDF plugins for each language we want to use. "$HOME/.asdf/completions/asdf.bash"' > ~/.zshrcĮcho 'legacy_version_file = yes' > ~/.asdfrc First you install asdf, and then add it to your shell:Įcho '. Installing asdf is a simple two step process. The reason we use ASDF over rbenv, rvm or others is that ASDF can manage other languages like Node.js too. Next we're going to be installing Ruby using a version manager called ASDF. Open Terminal and run the following command: /bin/bash -c "$(curl -fsSL )" Installing Ruby When it asks you to install XCode CommandLine Tools, say yes. Homebrew comes with a very simple install script. Homebrew allows us to install and compile software packages easily from source. Installing Homebrewįirst, we need to install Homebrew. This guide will walk you through setting up Ruby and Rails on Apple Silicon. Ruby can run on Apple Silicon like M1 and M2 chips and Intel Macs just fine. We have to comment out or replace the original insert statement or else we will get the error mentioned above: // client.We will be setting up a Ruby on Rails development environment on macOS 13 Ventura. Let’s add some more records to the app_user table first before we query the data. In this section, we will look at how to execute a SELECT query and how the result can be processed. Open up the main.rs file and replace the code with the following: use postgres:: Querying the database and processing the results Let’s connect to the database in our Rust program. The postgres crate helps connect to the database. # See more keys and their definitions at Then let’s add some required dependencies to the Cargo.toml: Let’s create a new project cargo new rust-postgresql-tutorial. With the database set up out of the way, we can start our Rust project for connecting to the PostgreSQL database. We can list the databases with the command \list: Set up the Rust project If the command is successful the database was set up correctly. Then we can connect to the postgres database we configured in the docker-compose.yml using the psql command: psql -d postgres -U dboperator. We can enter the terminal of the PostgreSQL container using the following command: docker exec -ti rust-postgresql-tutorial_postgres_1 bash. Let’s check to see if the configuration created the database successfully. We can check to see the container running with the docker ps command: Checking to see if the database is running Then bringing everything down can be done with docker-compose down. If we want to run the database in a background process we can use docker-compose up -d. We can now run the database instance with the following command: docker-compose up. In this case, it will mean port 5243 on our localhost will be directed to port 5432 in the docker container. The port number in front of the “:” can be anything we like. The port number 5243 is the port number we will use in our code to connect to the database server. Let’s create a file called docker-compose.yaml with the following contents: version: "3.9" We are going to set up a simple docker-compose file that will start a PostgreSQL database instance and enable access for a specific user. In this case, we will use docker and docker-compose. Setting up the database with docker-composeįirst, we will briefly go over one of the ways how we can easily set up a PostgreSQL database for testing purposes. For some basic information on docker please see my article on it here: What is Docker and why is it used: quick primer. Some Rust programming knowledge is required to follow this tutorial.ĭocker installed. The example code repository can be found on my GitHub: here. A database is often an important component for any data-based backend system.įor example, the Rust REST API project we made a while ago could really use a database connection implementation: How to implement a Rust REST API with warp. In this tutorial, we will learn how to connect to and manage a PostgreSQL database using the Rust programming language.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |