Skip to content

Commit 176ee7b

Browse files
committed
got inital sqlite working
1 parent 25ef11e commit 176ee7b

File tree

7 files changed

+40
-12
lines changed

7 files changed

+40
-12
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ Cargo.lock
1818

1919
# rust
2020
**/target/*
21+
22+
# sqlite
23+
*.db-shm
24+
*.db-wal

cri/build.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
66
.build_server(true)
77
.compile(PROTO_FILES, &["vendor/"])
88
.expect("Failed to generate GRPC bindings");
9-
109
Ok(())
1110
}

server/.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
DATABASE_URL='sqlite://al.db' # Or path to database file if using sqlite3.
1+
DATABASE_URL='sqlite:server/al.db' # Or path to database file if using sqlite3.

server/al.db

8 KB
Binary file not shown.

server/migrations/20230228224430.sql

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CREATE TABLE IF NOT EXISTS repositories (
2+
id INTEGER PRIMARY KEY NOT NULL,
3+
name TEXT NOT NULL,
4+
description TEXT NOT NULL,
5+
url TEXT NOT NULL,
6+
created_at TEXT NOT NULL,
7+
updated_at TEXT NOT NULL,
8+
pushed_at TEXT NOT NULL,
9+
pipelines TEXT NOT NULL,
10+
);
+4-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
use sqlx::any::AnyPool;
2-
use sqlx::database::Database;
3-
use sqlx::error::Error;
4-
use sqlx::pool::PoolConnection;
5-
use sqlx::postgres::PgPool;
6-
use sqlx::sqlite::{SqliteConnectOptions, SqlitePool};
1+
use sqlx::sqlite::{ SqlitePool};
2+
73

84
pub struct ConnectionManager {
9-
pool: AnyPool,
5+
pub pool: SqlitePool,
106
}
117

128
impl ConnectionManager {
139
pub async fn new(url: String) -> anyhow::Result<Self> {
14-
let pool = AnyPool::connect(&url).await?;
10+
let pool = SqlitePool::connect(&url).await?;
1511
Ok(Self { pool })
1612
}
1713
}

server/src/main.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
mod config;
22
mod database;
3-
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
3+
use actix_web::{get, post, App, HttpResponse, HttpServer, Responder};
44
use database::connection_manager::ConnectionManager;
5+
use std::env;
56

67
#[tokio::main]
7-
async fn main() -> std::io::Result<()> {
8+
async fn main() -> anyhow::Result<()> {
89
// Get the server config
910

1011
// Get the database connection manager
12+
//let con_man = ConnectionManager::new(env::var("DATABASE_URL")?).await?;
13+
14+
let con_man = ConnectionManager::new(env::var("DATABASE_URL")?).await?;
15+
16+
let mut con = con_man.pool.acquire().await?;
17+
18+
let id = sqlx::query!(
19+
r#"
20+
CREATE TABLE IF NOT EXISTS repositories (
21+
id INTEGER PRIMARY KEY,
22+
description TEXT NOT NULL
23+
)
24+
"#,
25+
)
26+
.execute(&mut con)
27+
.await?
28+
.last_insert_rowid();
1129

1230
// start listening to github webhook
1331

@@ -16,6 +34,7 @@ async fn main() -> std::io::Result<()> {
1634
.bind(("127.0.0.1", 8080))?
1735
.run()
1836
.await
37+
.map_err(|e| e.into())
1938
}
2039

2140
#[get("/agent/{id}")]

0 commit comments

Comments
 (0)