generated from lucien/actix-react-template
back_end #6
3 changed files with 13 additions and 8 deletions
Binary file not shown.
|
@ -1,9 +1,14 @@
|
||||||
use sqlite::{Connection, State, Error};
|
use sqlite::{Connection, OpenFlags};
|
||||||
|
|
||||||
pub fn init() -> sqlite::Result<()> {
|
pub fn init() -> sqlite::Result<()> {
|
||||||
let conn = Connection::open("./data/data.db")?;
|
let conn = Connection::open_with_flags(
|
||||||
|
"./data/data.db",
|
||||||
|
OpenFlags::new()
|
||||||
|
.with_create()
|
||||||
|
.with_read_write()
|
||||||
|
);
|
||||||
|
|
||||||
conn.execute(
|
conn?.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS articles (
|
"CREATE TABLE IF NOT EXISTS articles (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL,
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
mod create_db;
|
||||||
|
use create_db::init;
|
||||||
|
|
||||||
use actix_web::{App, HttpServer, get, Responder, HttpResponse, http::header::ContentType};
|
use actix_web::{App, HttpServer, get, Responder, HttpResponse, http::header::ContentType};
|
||||||
use actix_files::Files;
|
use actix_files::Files;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sqlite::{Connection, State, Error};
|
use sqlite::{Connection, State};
|
||||||
|
|
||||||
mod create_db;
|
|
||||||
use create_db::init;
|
|
||||||
|
|
||||||
#[get("/api/hello")]
|
#[get("/api/hello")]
|
||||||
async fn hello() -> impl Responder {
|
async fn hello() -> impl Responder {
|
||||||
|
@ -48,7 +48,7 @@ async fn api() -> impl Responder {
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> Result<(), std::io::Error> {
|
async fn main() -> Result<(), std::io::Error> {
|
||||||
init();
|
let _ = init();
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue