add source to notes schema

This commit is contained in:
anna 2022-12-18 17:38:19 +01:00
parent 44807f408f
commit 808b03b817
Signed by: fef
GPG key ID: EC22E476DC2D3D84
3 changed files with 19 additions and 11 deletions

View file

@ -1,12 +1,15 @@
CREATE TABLE notes (
id BIGSERIAL PRIMARY KEY,
account_id BIGINT REFERENCES accounts(id),
account_id BIGINT REFERENCES accounts (id),
uri VARCHAR,
content TEXT NOT NULL,
source TEXT DEFAULT NULL,
summary TEXT DEFAULT NULL,
sensitive BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMP NOT NULL DEFAULT now(),
updated_at TIMESTAMP NOT NULL DEFAULT now()
);
CREATE INDEX index_notes_on_account_id ON notes (account_id);
CREATE UNIQUE INDEX index_notes_on_uri ON notes (uri);
CREATE INDEX index_notes_on_created_at ON notes (created_at);

View file

@ -31,9 +31,9 @@ impl PgNoteDataSource {
{
let id: Id = id.into();
let notes: Vec<Note> = sqlx::query_as(
"SELECT * FROM notes \
WHERE account_id = $1 AND created_at < $1 \
ORDER BY created_at \
"SELECT * FROM notes
WHERE account_id = $1 AND created_at < $1
ORDER BY created_at
LIMIT 20",
)
.bind(id)
@ -49,17 +49,20 @@ impl PgNoteDataSource {
{
let new = new.into();
let note: Note = sqlx::query_as(
"INSERT INTO notes ( \
account_id, \
uri, \
content, \
summary, \
sensitive \
) VALUES ($1, $2, $3, $4, $5)",
"INSERT INTO notes (
account_id,
uri,
content,
source,
summary,
sensitive
) VALUES ($1, $2, $3, $4, $5, $6)
RETURNING *",
)
.bind(new.account_id)
.bind(new.uri)
.bind(new.content)
.bind(new.source)
.bind(new.summary)
.bind(new.sensitive)
.fetch_one(&self.pool)

View file

@ -10,6 +10,7 @@ pub struct Note {
pub account_id: Id,
pub uri: Option<String>,
pub content: String,
pub source: Option<String>,
pub summary: Option<String>,
pub sensitive: bool,
pub created_at: NaiveDateTime,
@ -20,6 +21,7 @@ pub struct NewNote {
pub account_id: Id,
pub uri: String,
pub content: String,
pub source: Option<String>,
pub summary: Option<String>,
pub sensitive: bool,
}