To start the project, you need to run the following command: cargo runĪs simple as that! When you access the endpoint (the GET), you may see the following:
#Rust sqlite how to#
Then, you might define the routes individually, only this way Actix will know how to apply the routing methods we’ve created before.įinally, inform the address for this server to bind at (localhost + port) and run it.
![rust sqlite rust sqlite](https://res.cloudinary.com/practicaldev/image/fetch/s--8dt31RrD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1rtq50tg8wbf7zoofm98.png)
It provides us with a data() method that acts by feeding the HTTP server with a data source to look at. Then, we send it directly to the new App created. route("/getusers", web::get().to(routes::get_users))įirst, we’re setting up the database by calling its pool builder. build(ConnectionManager:: ::new(database_url)) Let database_url = std::env::var("DATABASE_URL").expect("NOT FOUND") Serde : a framework for serializing and deserializing Rust data structures efficiently and generically.Īnd this is how your Cargo.toml dependencies section should look like: ĭiesel =.dotenv for environment variables management.R2d2 is a good connection pool for Rust, which will be useful for our example. Diesel’s main dependency allowing both SQLite and r2d2 features.Actix’s web and rt : the main dependency for Actix web development and a runtime implementation that runs everything on the current thread, respectively.Regarding the dependencies we’ll need to add, let’s sum them up below:
![rust sqlite rust sqlite](https://write.rog.gr/img/social_image.png)
This will create some folders and files containing the main.rs with a Hello World example, and the Cargo.tom file which defines the list of dependencies of the current Rust project. So, within a folder of your choice, run the following command to create a new Rust project: $ cargo new rust-sqlite-api Once you’ve installed Rust, you’ll get along the Cargo (Rust’s package manager) commands who will be responsible for the scaffolding of our new project.
#Rust sqlite install#
If you’re on Mac, for example, you’d need to run the following: $ brew install sqlite
#Rust sqlite drivers#
Since we’re going to use SQLite as the default database, you don’t have to install anything, except for the proper drivers for your computer. You can find proper instructions for that in our previous article. Let’s dive in! Setupįirst of all, you need to make sure that Rust is installed in your machine. In this article, we’re going to explore these frameworks in action through the implementation of a CRUD application of users, made with Actix, Diesel, and SQLite. Like all major languages, Rust has grown in a rich community that embraces the open-source creation of frameworks and tools to enhance its development experience.Īmong them, we can find frameworks like Actix Web for web development, and Diesel for integrating your applications with databases in an easier way.
![rust sqlite rust sqlite](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/34410/f7d83934-0da6-9b6c-8220-5bf695464e83.png)
If you need more sophisticated stuff, like web applications and APIs, well, you’re in the right place. It means that a ton of different programs with broad objectives can be created with Rust. As we’ve already seen in our previous introductory article about the Rust programming language, other than fast it is also versatile.