pub struct ParseCache { /* private fields */ }Expand description
A thread-safe LRU cache for parsed SQL ASTs.
Avoids re-parsing identical SQL strings. Cache capacity is configurable.
Both the SQL text and the SqlDialect are used as the cache key so that
the same query text parsed under different dialects is stored separately.
§Example
use oxisql_parse::{ParseCache, SqlDialect};
let cache = ParseCache::new(32);
let stmts = cache.parse("SELECT 1", SqlDialect::Generic).unwrap();
assert_eq!(stmts.len(), 1);
assert_eq!(cache.len(), 1);Implementations§
Source§impl ParseCache
impl ParseCache
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new cache with the given capacity.
If capacity is 0 it is silently promoted to 1 so the cache is always
functional.
Sourcepub fn parse(
&self,
sql: &str,
dialect: SqlDialect,
) -> Result<Vec<Statement>, OxiSqlError>
pub fn parse( &self, sql: &str, dialect: SqlDialect, ) -> Result<Vec<Statement>, OxiSqlError>
Parse sql with dialect, returning the cached result if available.
On a cache miss the SQL is parsed and the result stored before returning.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ParseCache
impl RefUnwindSafe for ParseCache
impl Send for ParseCache
impl Sync for ParseCache
impl Unpin for ParseCache
impl UnsafeUnpin for ParseCache
impl UnwindSafe for ParseCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more