mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
remove name field
This commit is contained in:
parent
d00364bbb9
commit
2df86b27ab
1 changed files with 7 additions and 12 deletions
|
|
@ -6,7 +6,6 @@ pub struct Row {
|
||||||
//pub profile_id: i64,
|
//pub profile_id: i64,
|
||||||
pub is_default: bool,
|
pub is_default: bool,
|
||||||
pub query: String,
|
pub query: String,
|
||||||
pub name: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Database {
|
pub struct Database {
|
||||||
|
|
@ -38,7 +37,7 @@ impl Database {
|
||||||
|
|
||||||
/// Create new record in database
|
/// Create new record in database
|
||||||
/// * return last insert ID on success
|
/// * return last insert ID on success
|
||||||
pub fn add(&self, query: String, name: Option<String>, is_default: bool) -> Result<i64, Error> {
|
pub fn add(&self, query: String, is_default: bool) -> Result<i64, Error> {
|
||||||
// Begin new transaction
|
// Begin new transaction
|
||||||
let mut writable = self.connection.write().unwrap(); // @TODO handle
|
let mut writable = self.connection.write().unwrap(); // @TODO handle
|
||||||
let tx = writable.transaction()?;
|
let tx = writable.transaction()?;
|
||||||
|
|
@ -48,7 +47,7 @@ impl Database {
|
||||||
// make sure only one default provider in set
|
// make sure only one default provider in set
|
||||||
reset(&tx, *self.profile_id, !is_default)?;
|
reset(&tx, *self.profile_id, !is_default)?;
|
||||||
}
|
}
|
||||||
insert(&tx, *self.profile_id, query, name, is_default)?;
|
insert(&tx, *self.profile_id, query, is_default)?;
|
||||||
|
|
||||||
// Hold insert ID for result
|
// Hold insert ID for result
|
||||||
let id = last_insert_id(&tx);
|
let id = last_insert_id(&tx);
|
||||||
|
|
@ -87,7 +86,6 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||||
`profile_id` INTEGER NOT NULL,
|
`profile_id` INTEGER NOT NULL,
|
||||||
`is_default` INTEGER NOT NULL,
|
`is_default` INTEGER NOT NULL,
|
||||||
`query` TEXT NOT NULL,
|
`query` TEXT NOT NULL,
|
||||||
`name` VARCHAR(64),
|
|
||||||
|
|
||||||
FOREIGN KEY (`profile_id`) REFERENCES `profile` (`id`)
|
FOREIGN KEY (`profile_id`) REFERENCES `profile` (`id`)
|
||||||
)",
|
)",
|
||||||
|
|
@ -99,23 +97,21 @@ fn insert(
|
||||||
tx: &Transaction,
|
tx: &Transaction,
|
||||||
profile_id: i64,
|
profile_id: i64,
|
||||||
query: String,
|
query: String,
|
||||||
name: Option<String>,
|
|
||||||
is_default: bool,
|
is_default: bool,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"INSERT INTO `profile_search` (
|
"INSERT INTO `profile_search` (
|
||||||
`profile_id`,
|
`profile_id`,
|
||||||
`is_default`,
|
`is_default`,
|
||||||
`query`,
|
`query`
|
||||||
`name`
|
) VALUES (?, ?, ?)",
|
||||||
) VALUES (?, ?, ?, ?)",
|
(profile_id, is_default, query),
|
||||||
(profile_id, is_default, query, name),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select(tx: &Transaction, profile_id: i64) -> Result<Vec<Row>, Error> {
|
fn select(tx: &Transaction, profile_id: i64) -> Result<Vec<Row>, Error> {
|
||||||
let mut stmt = tx.prepare(
|
let mut stmt = tx.prepare(
|
||||||
"SELECT `id`, `profile_id`, `is_default`, `query`, `name`
|
"SELECT `id`, `profile_id`, `is_default`, `query`
|
||||||
FROM `profile_search`
|
FROM `profile_search`
|
||||||
WHERE `profile_id` = ?",
|
WHERE `profile_id` = ?",
|
||||||
)?;
|
)?;
|
||||||
|
|
@ -125,8 +121,7 @@ fn select(tx: &Transaction, profile_id: i64) -> Result<Vec<Row>, Error> {
|
||||||
id: row.get(0)?,
|
id: row.get(0)?,
|
||||||
//profile_id: row.get(1)?,
|
//profile_id: row.get(1)?,
|
||||||
is_default: row.get(2)?,
|
is_default: row.get(2)?,
|
||||||
name: row.get(3)?,
|
query: row.get(3)?,
|
||||||
query: row.get(4)?,
|
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue