Skip to content

Commit 620fe34

Browse files
authored
Merge pull request #2394 from fermyon/update-libsql
Update libsql to latest version
2 parents a400e3f + 99ef32f commit 620fe34

File tree

6 files changed

+152
-65
lines changed

6 files changed

+152
-65
lines changed

Cargo.lock

Lines changed: 49 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sqlite-libsql/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ async-trait = "0.1.68"
99
anyhow = "1.0"
1010
# We don't actually use rusqlite itself, but we'd like the same bundled
1111
# libsqlite3-sys as used by spin-sqlite-inproc.
12-
rusqlite = { version = "0.29.0", features = [ "bundled" ] }
12+
rusqlite = { version = "0.29.0", features = ["bundled"] }
1313
spin-sqlite = { path = "../sqlite" }
1414
spin-world = { path = "../world" }
1515
sqlparser = "0.34"
16-
libsql = { version = "0.2.0-alpha.1", features = ["remote"], default-features = false }
16+
libsql = { version = "0.3.2", features = ["remote"], default-features = false }
1717
tokio = { version = "1", features = ["full"] }

crates/sqlite-libsql/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ pub struct LibsqlClient {
66
}
77

88
impl LibsqlClient {
9-
pub fn create(url: &str, token: String) -> anyhow::Result<Self> {
10-
let db = libsql::Database::open_remote(url, token)?;
9+
pub async fn create(url: String, token: String) -> anyhow::Result<Self> {
10+
let db = libsql::Builder::new_remote(url, token).build().await?;
1111
let inner = db.connect()?;
1212
Ok(Self { inner })
1313
}
@@ -28,7 +28,9 @@ impl spin_sqlite::Connection for LibsqlClient {
2828

2929
Ok(sqlite::QueryResult {
3030
columns: columns(&result),
31-
rows: convert_rows(result).map_err(|e| sqlite::Error::Io(e.to_string()))?,
31+
rows: convert_rows(result)
32+
.await
33+
.map_err(|e| sqlite::Error::Io(e.to_string()))?,
3234
})
3335
}
3436

@@ -45,12 +47,12 @@ fn columns(rows: &libsql::Rows) -> Vec<String> {
4547
.collect()
4648
}
4749

48-
fn convert_rows(mut rows: libsql::Rows) -> anyhow::Result<Vec<RowResult>> {
50+
async fn convert_rows(mut rows: libsql::Rows) -> anyhow::Result<Vec<RowResult>> {
4951
let mut result_rows = vec![];
5052

5153
let column_count = rows.column_count();
5254

53-
while let Some(row) = rows.next()? {
55+
while let Some(row) = rows.next().await? {
5456
result_rows.push(convert_row(row, column_count));
5557
}
5658

crates/trigger/src/runtime_config.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,24 @@ impl RuntimeConfig {
110110
}
111111

112112
/// Return an iterator of named configured [`SqliteDatabase`]s.
113-
pub fn sqlite_databases(
113+
pub async fn sqlite_databases(
114114
&self,
115115
) -> Result<impl IntoIterator<Item = (String, Arc<dyn Connection>)>> {
116116
let mut databases = HashMap::new();
117117
// Insert explicitly-configured databases
118118
for opts in self.opts_layers() {
119119
for (name, database) in &opts.sqlite_databases {
120120
if !databases.contains_key(name) {
121-
let store = database.build(opts)?;
121+
let store = database.build(opts).await?;
122122
databases.insert(name.to_owned(), store);
123123
}
124124
}
125125
}
126126
// Upsert default store
127127
if !databases.contains_key("default") {
128-
let store = SqliteDatabaseOpts::default(self).build(&RuntimeConfigOpts::default())?;
128+
let store = SqliteDatabaseOpts::default(self)
129+
.build(&RuntimeConfigOpts::default())
130+
.await?;
129131
databases.insert("default".into(), store);
130132
}
131133
Ok(databases.into_iter())

crates/trigger/src/runtime_config/sqlite.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub(crate) async fn build_component(
1515
) -> anyhow::Result<SqliteComponent> {
1616
let databases: HashMap<_, _> = runtime_config
1717
.sqlite_databases()
18+
.await
1819
.context("Failed to build sqlite component")?
1920
.into_iter()
2021
.collect();
@@ -88,10 +89,13 @@ impl SqliteDatabaseOpts {
8889
Self::Spin(SpinSqliteDatabaseOpts::default(runtime_config))
8990
}
9091

91-
pub fn build(&self, config_opts: &RuntimeConfigOpts) -> anyhow::Result<Arc<dyn Connection>> {
92+
pub async fn build(
93+
&self,
94+
config_opts: &RuntimeConfigOpts,
95+
) -> anyhow::Result<Arc<dyn Connection>> {
9296
match self {
9397
Self::Spin(opts) => opts.build(config_opts),
94-
Self::Libsql(opts) => opts.build(),
98+
Self::Libsql(opts) => opts.build().await,
9599
}
96100
}
97101
}
@@ -135,14 +139,17 @@ pub struct LibsqlOpts {
135139
}
136140

137141
impl LibsqlOpts {
138-
fn build(&self) -> anyhow::Result<Arc<dyn Connection>> {
139-
let url = &check_url(&self.url).with_context(|| {
140-
format!(
141-
"unexpected libSQL URL '{}' in runtime config file ",
142-
self.url
143-
)
144-
})?;
142+
async fn build(&self) -> anyhow::Result<Arc<dyn Connection>> {
143+
let url = check_url(&self.url)
144+
.with_context(|| {
145+
format!(
146+
"unexpected libSQL URL '{}' in runtime config file ",
147+
self.url
148+
)
149+
})?
150+
.to_owned();
145151
let client = spin_sqlite_libsql::LibsqlClient::create(url, self.token.clone())
152+
.await
146153
.context("failed to create SQLite client")?;
147154
Ok(Arc::new(client))
148155
}

0 commit comments

Comments
 (0)