Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

rbdc-drivers

License

NotificationsYou must be signed in to change notification settings

rbatis/rbdc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RBDC driver abstract

how to define my driver to support rbdc driver?

just only impl this traits(6)

use rbdc::db::{Driver,MetaData,Row,Connection,ConnectOptions,Placeholder};pubstructYourDriver{}implDriverforYourDriver{}pubstructYourMetaData{}implMetaDataforYourMetaData{}pubstructYourRow{}implRowforYourRow{}pubstructYourConnection{}implConnectionforYourConnection{}pubstructYourConnectOptions{}implConnectOptionsforYourConnectOptions{}pubstructYourPlaceholder{}implPlaceholderforYourPlaceholder{}

how to use my driver?

use rbdc_sqlite::SqliteDriver;use rbdc::db::{Connection};use rbdc::Error;use rbdc::pool::ConnManager;use rbdc::pool::Pool;use rbdc_pool_fast::FastPool;#[tokio::main]asyncfnmain() ->Result<(),Error>{let pool =FastPool::new(ConnManager::new(SqliteDriver{},"sqlite://target/test.db")?)?;letmut conn = pool.get().await?;// selectlet v = conn.get_values("select * from sqlite_master",vec![]).await?;println!("{}", rbs::Value::Array(v));// update/deletelet r = conn.exec("update table set name='a' where id = 1",vec![]).await?;println!("{}", r);Ok(())}

FAQ

How should I implement a driver for databases with blocking APIs?

For database drivers with blocking APIs, follow the pattern inrbdc-sqlite using theflume channel library:

// Key components:// 1. Dedicated worker thread per connection// 2. Command channels for communicationpubstructYourConnection{worker:ConnectionWorker,}structConnectionWorker{command_tx: flume::Sender<Command>,}enumCommand{Execute{/* ... */},Query{/* ... */},}

Benefits:

  • Prevents blocking the async runtime
  • Provides thread safety
  • Maintains a clean async interface

Why doesConnection require bothSend andSync?

Connection: Send + Sync is required because:

  1. Thread Safety: Connections may be shared across tasks on different threads when using Tokio
  2. Pool Implementation: Connection pools need thread-safe access to connections

When implementing for non-thread-safe databases:

// SAFETY: YourConnection is thread-safe because:// 1. Database operations run on a dedicated worker thread// 2. Communication uses thread-safe channelsunsafeimplSyncforYourConnection{}

Improper implementation can cause data races and undefined behavior.

About

rbdc-drivers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp