|
1 |
| -use std::{ |
2 |
| - net::TcpStream, |
3 |
| - sync::Arc, |
4 |
| -}; |
| 1 | +use std::{net::TcpStream, sync::Arc}; |
5 | 2 |
|
6 | 3 | use idesyde_core::{
|
7 |
| - merge_identification_results, DecisionModel, DesignModel, |
8 |
| - IdentificationResult, IdentificationRuleLike, Module, OpaqueDecisionModel, OpaqueDesignModel, |
| 4 | + merge_identification_results, DecisionModel, DesignModel, IdentificationResult, |
| 5 | + IdentificationRuleLike, Module, OpaqueDecisionModel, OpaqueDesignModel, |
9 | 6 | };
|
10 | 7 |
|
11 | 8 | use log::debug;
|
12 |
| -use rusqlite::params; |
13 | 9 | use tungstenite::WebSocket;
|
14 | 10 |
|
15 | 11 | use rayon::prelude::*;
|
@@ -131,7 +127,6 @@ impl Iterator for ExternalServerIdentifiticationIterator {
|
131 | 127 | }
|
132 | 128 | }
|
133 | 129 |
|
134 |
| - |
135 | 130 | impl Drop for ExternalServerIdentifiticationIterator {
|
136 | 131 | fn drop(&mut self) {
|
137 | 132 | if self.websocket.can_write() {
|
@@ -202,91 +197,91 @@ pub fn identification_procedure(
|
202 | 197 | (identified, messages)
|
203 | 198 | }
|
204 | 199 |
|
205 |
| -pub fn get_sqlite_for_identification(url: &str) -> Result<rusqlite::Connection, rusqlite::Error> { |
206 |
| - let conn = rusqlite::Connection::open(url)?; |
207 |
| - conn.execute( |
208 |
| - "CREATE TABLE IF NOT EXISTS decision_models ( |
209 |
| - id INTEGER PRIMARY KEY, |
210 |
| - category TEXT NOT NULL, |
211 |
| - body_cbor BLOB, |
212 |
| - body_msgpack BLOB, |
213 |
| - body_json JSON NOT NULL, |
214 |
| - UNIQUE (category, body_json) |
215 |
| - )", |
216 |
| - [], |
217 |
| - )?; |
218 |
| - conn.execute( |
219 |
| - "CREATE TABLE IF NOT EXISTS design_models ( |
220 |
| - id INTEGER PRIMARY KEY, |
221 |
| - category TEXT NOT NULL, |
222 |
| - format TEXT NOT NULL, |
223 |
| - body TEXT NOT NULL, |
224 |
| - UNIQUE (format, category, body) |
225 |
| - )", |
226 |
| - [], |
227 |
| - )?; |
228 |
| - conn.execute( |
229 |
| - "CREATE TABLE IF NOT EXISTS part ( |
230 |
| - decision_model_id INTEGER NOT NULL, |
231 |
| - element_name TEXT NOT NULL, |
232 |
| - FOREIGN KEY (decision_model_id) REFERENCES decision_models (id), |
233 |
| - UNIQUE (decision_model_id, element_name) |
234 |
| - )", |
235 |
| - [], |
236 |
| - )?; |
237 |
| - conn.execute( |
238 |
| - "CREATE TABLE IF NOT EXISTS elems ( |
239 |
| - design_model_id INTEGER NOT NULL, |
240 |
| - element_name TEXT NOT NULL, |
241 |
| - FOREIGN KEY (design_model_id) REFERENCES decision_models (id), |
242 |
| - UNIQUE (design_model_id, element_name) |
243 |
| - )", |
244 |
| - [], |
245 |
| - )?; |
246 |
| - Ok(conn) |
247 |
| -} |
| 200 | +// pub fn get_sqlite_for_identification(url: &str) -> Result<rusqlite::Connection, rusqlite::Error> { |
| 201 | +// let conn = rusqlite::Connection::open(url)?; |
| 202 | +// conn.execute( |
| 203 | +// "CREATE TABLE IF NOT EXISTS decision_models ( |
| 204 | +// id INTEGER PRIMARY KEY, |
| 205 | +// category TEXT NOT NULL, |
| 206 | +// body_cbor BLOB, |
| 207 | +// body_msgpack BLOB, |
| 208 | +// body_json JSON NOT NULL, |
| 209 | +// UNIQUE (category, body_json) |
| 210 | +// )", |
| 211 | +// [], |
| 212 | +// )?; |
| 213 | +// conn.execute( |
| 214 | +// "CREATE TABLE IF NOT EXISTS design_models ( |
| 215 | +// id INTEGER PRIMARY KEY, |
| 216 | +// category TEXT NOT NULL, |
| 217 | +// format TEXT NOT NULL, |
| 218 | +// body TEXT NOT NULL, |
| 219 | +// UNIQUE (format, category, body) |
| 220 | +// )", |
| 221 | +// [], |
| 222 | +// )?; |
| 223 | +// conn.execute( |
| 224 | +// "CREATE TABLE IF NOT EXISTS part ( |
| 225 | +// decision_model_id INTEGER NOT NULL, |
| 226 | +// element_name TEXT NOT NULL, |
| 227 | +// FOREIGN KEY (decision_model_id) REFERENCES decision_models (id), |
| 228 | +// UNIQUE (decision_model_id, element_name) |
| 229 | +// )", |
| 230 | +// [], |
| 231 | +// )?; |
| 232 | +// conn.execute( |
| 233 | +// "CREATE TABLE IF NOT EXISTS elems ( |
| 234 | +// design_model_id INTEGER NOT NULL, |
| 235 | +// element_name TEXT NOT NULL, |
| 236 | +// FOREIGN KEY (design_model_id) REFERENCES decision_models (id), |
| 237 | +// UNIQUE (design_model_id, element_name) |
| 238 | +// )", |
| 239 | +// [], |
| 240 | +// )?; |
| 241 | +// Ok(conn) |
| 242 | +// } |
248 | 243 |
|
249 |
| -pub fn save_decision_model_sqlite<T: DecisionModel + ?Sized>( |
250 |
| - url: &str, |
251 |
| - decision_model: &T, |
252 |
| -) -> Result<usize, rusqlite::Error> { |
253 |
| - let conn = get_sqlite_for_identification(url)?; |
254 |
| - let id = conn.execute( |
255 |
| - "INSERT INTO decision_models (category, body_cbor, body_msgpack, body_json) VALUES (?1, ?2, ?3, ?4)", params![ |
256 |
| - decision_model.category(), |
257 |
| - decision_model.body_as_cbor(), |
258 |
| - decision_model.body_as_msgpack(), |
259 |
| - decision_model.body_as_json() |
260 |
| - ] |
261 |
| - )?; |
262 |
| - let mut stmt = |
263 |
| - conn.prepare("INSERT INTO part (decision_model_id, element_name) VALUES (?1, ?2)")?; |
264 |
| - for elem in decision_model.part() { |
265 |
| - stmt.execute(params![id, elem])?; |
266 |
| - } |
267 |
| - Ok(id) |
268 |
| -} |
| 244 | +// pub fn save_decision_model_sqlite<T: DecisionModel + ?Sized>( |
| 245 | +// url: &str, |
| 246 | +// decision_model: &T, |
| 247 | +// ) -> Result<usize, rusqlite::Error> { |
| 248 | +// let conn = get_sqlite_for_identification(url)?; |
| 249 | +// let id = conn.execute( |
| 250 | +// "INSERT INTO decision_models (category, body_cbor, body_msgpack, body_json) VALUES (?1, ?2, ?3, ?4)", params![ |
| 251 | +// decision_model.category(), |
| 252 | +// decision_model.body_as_cbor(), |
| 253 | +// decision_model.body_as_msgpack(), |
| 254 | +// decision_model.body_as_json() |
| 255 | +// ] |
| 256 | +// )?; |
| 257 | +// let mut stmt = |
| 258 | +// conn.prepare("INSERT INTO part (decision_model_id, element_name) VALUES (?1, ?2)")?; |
| 259 | +// for elem in decision_model.part() { |
| 260 | +// stmt.execute(params![id, elem])?; |
| 261 | +// } |
| 262 | +// Ok(id) |
| 263 | +// } |
269 | 264 |
|
270 |
| -pub fn save_design_model_sqlite<T: DesignModel + ?Sized>( |
271 |
| - url: &str, |
272 |
| - design_model: &T, |
273 |
| -) -> Result<usize, rusqlite::Error> { |
274 |
| - let conn = get_sqlite_for_identification(url)?; |
275 |
| - let id = conn.execute( |
276 |
| - "INSERT INTO design_models (category, format, body) VALUES (?1, ?2, ?3)", |
277 |
| - params![ |
278 |
| - design_model.category(), |
279 |
| - design_model.format(), |
280 |
| - design_model.body_as_string() |
281 |
| - ], |
282 |
| - )?; |
283 |
| - let mut stmt = |
284 |
| - conn.prepare("INSERT INTO elems (design_model_id, element_name) VALUES (?1, ?2)")?; |
285 |
| - for elem in design_model.elements() { |
286 |
| - stmt.execute(params![id, elem])?; |
287 |
| - } |
288 |
| - Ok(id) |
289 |
| -} |
| 265 | +// pub fn save_design_model_sqlite<T: DesignModel + ?Sized>( |
| 266 | +// url: &str, |
| 267 | +// design_model: &T, |
| 268 | +// ) -> Result<usize, rusqlite::Error> { |
| 269 | +// let conn = get_sqlite_for_identification(url)?; |
| 270 | +// let id = conn.execute( |
| 271 | +// "INSERT INTO design_models (category, format, body) VALUES (?1, ?2, ?3)", |
| 272 | +// params![ |
| 273 | +// design_model.category(), |
| 274 | +// design_model.format(), |
| 275 | +// design_model.body_as_string() |
| 276 | +// ], |
| 277 | +// )?; |
| 278 | +// let mut stmt = |
| 279 | +// conn.prepare("INSERT INTO elems (design_model_id, element_name) VALUES (?1, ?2)")?; |
| 280 | +// for elem in design_model.elements() { |
| 281 | +// stmt.execute(params![id, elem])?; |
| 282 | +// } |
| 283 | +// Ok(id) |
| 284 | +// } |
290 | 285 |
|
291 | 286 | // #[derive(Debug, PartialEq, Eq, Hash)]
|
292 | 287 | // pub struct ExternalIdentificationModule {
|
|
0 commit comments