···11-# This file contains settings for `cargo hakari`.
22-# See https://docs.rs/cargo-hakari/latest/cargo_hakari/config for a full list of options.
33-44-hakari-package = "weaver-workspace-hack"
55-66-# Format version for hakari's output. Version 4 requires cargo-hakari 0.9.22 or above.
77-dep-format-version = "4"
88-99-# Setting workspace.resolver = "2" in the root Cargo.toml is HIGHLY recommended.
1010-# Hakari works much better with the new feature resolver.
1111-# For more about the new feature resolver, see:
1212-# https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver
1313-resolver = "2"
1414-1515-# Add triples corresponding to platforms commonly used by developers here.
1616-# https://doc.rust-lang.org/rustc/platform-support.html
1717-platforms = [
1818- # "x86_64-unknown-linux-gnu",
1919- # "x86_64-apple-darwin",
2020- # "x86_64-pc-windows-msvc",
2121-]
2222-2323-# Write out exact versions rather than a semver range. (Defaults to false.)
2424-# exact-versions = true
···3232chrono = { version = "0.4" }
3333serde_json = "1.0"
34343535+diesel = { version = "2.3", features = ["sqlite", "returning_clauses_for_sqlite_3_35", "chrono", "serde_json"] }
3636+diesel_migrations = { version = "2.3", features = ["sqlite"] }
3737+3838+3939+[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
4040+sqlite-wasm-rs = { version = "0.4", features = ["relaxed-idb"] }
4141+4242+4343+3544[target.'cfg(target_arch = "wasm32")'.dependencies]
3645time = { version = "0.3", features = ["wasm-bindgen"] }
3746console_error_panic_hook = "0.1"
+9
crates/weaver-app/diesel.toml
···11+# For documentation on how to configure this file,
22+# see https://diesel.rs/guides/configuring-diesel-cli
33+44+[print_schema]
55+file = "src/schema.rs"
66+custom_type_derives = ["diesel::query_builder::QueryId", "Clone", "std::fmt::Debug", "jacquard::IntoStatic"]
77+88+[migrations_directory]
99+dir = "/home/orual/Projects/weaver.sh/crates/weaver-app/migrations"
···11--- This file was automatically created by Diesel to setup helper functions
22--- and other internal bookkeeping. This file is safe to edit, any future
33--- changes will be added to existing projects as new migrations.
44-55-DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
66-DROP FUNCTION IF EXISTS diesel_set_updated_at();
···11--- This file was automatically created by Diesel to setup helper functions
22--- and other internal bookkeeping. This file is safe to edit, any future
33--- changes will be added to existing projects as new migrations.
44-55-66-77-88--- Sets up a trigger for the given table to automatically set a column called
99--- `updated_at` whenever the row is modified (unless `updated_at` was included
1010--- in the modified columns)
1111---
1212--- # Example
1313---
1414--- ```sql
1515--- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
1616---
1717--- SELECT diesel_manage_updated_at('users');
1818--- ```
1919-CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
2020-BEGIN
2121- EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
2222- FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
2323-END;
2424-$$ LANGUAGE plpgsql;
2525-2626-CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
2727-BEGIN
2828- IF (
2929- NEW IS DISTINCT FROM OLD AND
3030- NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
3131- ) THEN
3232- NEW.updated_at := current_timestamp;
3333- END IF;
3434- RETURN NEW;
3535-END;
3636-$$ LANGUAGE plpgsql;
···11create table if not exists registrations (
22- id serial primary key,
22+ id integer not null primary key autoincrement,
33 domain text not null unique,
44 did text not null,
55 secret text not null,
66- created timestamp
77- with
88- time zone not null default (now () at time zone 'utc'),
99- registered text
66+ created timestamp not null default (datetime('now')),
77+ registered text
108);
1191210create table if not exists public_keys (
1313- id serial primary key,
1111+ id integer not null primary key autoincrement,
1412 did text not null,
1513 name text not null,
1614 key_contents text not null,
1715 rkey text not null,
1818- created timestamp
1919- with
2020- time zone not null default (now () at time zone 'utc'),
2121- unique (did, name, key_contents)
1616+ created timestamp not null default (datetime('now')),
1717+ unique (did, name, key_contents)
2218);
23192420create table if not exists follows (
2521 user_did text not null,
2622 subject_did text not null,
2723 rkey text not null,
2828- followed_at timestamp
2929- with
3030- time zone not null default (now () at time zone 'utc'),
3131- primary key (user_did, subject_did),
2424+ followed_at timestamp not null default (datetime('now')),
2525+ primary key (user_did, subject_did),
3226 check (user_did <> subject_did)
3327);
34283529create table if not exists _jetstream (
3636- id serial primary key,
3030+ id integer not null primary key autoincrement,
3731 last_time_us integer not null
3832);
39334034create table if not exists emails (
4141- id serial primary key,
3535+ id integer not null primary key autoincrement,
4236 did text not null,
4337 email text not null,
4444- verified integer not null default 0,
3838+ verified boolean not null default false,
4539 verification_code text not null,
4646- last_sent timestamp
4747- with
4848- time zone not null default (now () at time zone 'utc'),
4949- is_primary integer not null default 0,
5050- created timestamp
5151- with
5252- time zone not null default (now () at time zone 'utc'),
5353- unique (did, email)
4040+ last_sent timestamp not null default (datetime('now')),
4141+ is_primary boolean not null default false,
4242+ created timestamp not null default (datetime('now')),
4343+ unique (did, email)
5444);
55455646create table if not exists profile (
5747 -- id
5858- id serial primary key,
4848+ id integer not null primary key autoincrement,
5949 did text not null,
6050 -- data
6151 avatar text,
···6353 include_bluesky boolean not null default false,
6454 include_tangled boolean not null default false,
6555 location text,
6666- pinned_post jsonb,
6767- created_at timestamp
6868- with
6969- time zone default (now () at time zone 'utc'),
7070- -- constraints
7171- unique (did)
5656+ pinned_post text,
5757+ created_at timestamp default (datetime('now')),
5858+ -- constraints
5959+ unique (did)
7260);
73617462create table if not exists profile_links (
7563 -- id
7676- id serial primary key,
6464+ id integer not null primary key autoincrement,
7765 did text not null,
7866 -- data
7967 link text not null,
···83718472create table if not exists profile_pronouns (
8573 -- id
8686- id serial primary key,
7474+ id integer not null primary key autoincrement,
8775 did text not null,
8876 -- data
8977 pronoun text not null,
···93819482-- OAuth sessions table for jacquard ClientSessionData
9583create table if not exists oauth_sessions (
9696- id serial primary key,
8484+ id integer not null primary key autoincrement,
9785 -- Extracted from ClientSessionData for indexing
9886 did text not null,
9987 session_id text not null,
100100- -- Full ClientSessionData as jsonb
101101- session_data jsonb not null,
102102- created_at timestamp with time zone not null default (now() at time zone 'utc'),
103103- updated_at timestamp with time zone not null default (now() at time zone 'utc'),
8888+ -- Full ClientSessionData as JSON
8989+ session_data blob not null,
9090+ created_at timestamp not null default (datetime('now')),
9191+ updated_at timestamp not null default (datetime('now')),
10492 unique (did, session_id)
10593);
1069410795-- OAuth authorization requests table for jacquard AuthRequestData
10896create table if not exists oauth_auth_requests (
109109- id serial primary key,
9797+ id integer not null primary key autoincrement,
11098 -- Extracted from AuthRequestData for indexing
11199 state text not null unique,
112100 -- Optional DID if known at auth request time
113101 account_did text,
114114- -- Full AuthRequestData as jsonb
115115- auth_req_data jsonb not null,
116116- created_at timestamp with time zone not null default (now() at time zone 'utc'),
117117- expires_at timestamp with time zone not null default ((now() at time zone 'utc') + interval '10 minutes')
102102+ -- Full AuthRequestData as JSON
103103+ auth_req_data blob not null,
104104+ created_at timestamp not null default (datetime('now')),
105105+ expires_at timestamp not null default (datetime('now', '+10 minutes'))
118106);
119107120108-- Index for quick session lookups
+8-4
crates/weaver-index/src/db.rs
···44use diesel_async::RunQueryDsl;
55use diesel_async::pooled_connection::AsyncDieselConnectionManager;
66use diesel_async::pooled_connection::deadpool::Pool;
77+use diesel_async::sync_connection_wrapper::SyncConnectionWrapper;
7889#[derive(Clone)]
910pub struct Db {
1010- pub pool: Pool<diesel_async::AsyncPgConnection>,
1111+ pub pool: Pool<SyncConnectionWrapper<SqliteConnection>>,
1112}
12131314impl Db {
···2021 } else {
2122 std::env::var("DATABASE_URL").expect("DATABASE_URL must be set")
2223 };
2323- let config =
2424- AsyncDieselConnectionManager::<diesel_async::AsyncPgConnection>::new(database_url);
2424+ let config = AsyncDieselConnectionManager::<SyncConnectionWrapper<SqliteConnection>>::new(
2525+ database_url,
2626+ );
2527 let pool = Pool::builder(config)
2628 .build()
2729 .expect("Failed to create pool");
···3739 } else {
3840 std::env::var("DATABASE_URL").expect("DATABASE_URL must be set")
3941 };
4040- let mut connection = PgConnection::establish(&database_url)
4242+ let mut connection = SqliteConnection::establish(&database_url)
4143 .unwrap_or_else(|_| panic!("Error connecting to {}", database_url));
4244 // This will run the necessary migrations.
4345 //
···5759 }
5860 Ok(())
5961}
6262+6363+pub struct Runtime;