Skip to content

Commit

Permalink
fix(README.md): update repository disclaimer to provide more informat…
Browse files Browse the repository at this point in the history
…ion about the pre-release state and future plans

feat(index.js): export Compression enum from native binding to allow usage in JavaScript code
feat(cluster_config.rs): remove unused ClusterConfig struct
feat(cluster_config/compression.rs): add Compression enum and conversion to scylla::transport::Compression
feat(cluster_config/mod.rs): add compression field to ClusterConfig struct
feat(scylla_cluster.rs): add compression field to ScyllaCluster struct and use it when creating ScyllaSession
  • Loading branch information
Daniel-Boll committed Oct 14, 2023
2 parents 3848141 + 92eb0c1 commit 019902a
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 13 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<div align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://socialify.git.ci/daniel-boll/scylladb/image?font=Inter&language=1&name=1&pattern=Solid&theme=Dark">
<img src="https://socialify.git.ci/daniel-boll/scylladb/image?font=Inter&language=1&name=1&pattern=Solid&theme=Dark" alt="scylladb" width="640" height="320" />
</picture>
<a href="https://github.com/daniel-boll/scylla-javascript-driver">
<img src="assets/logo.png" alt="scylladb" width="640" />
</a>

<h4>🚀 JavaScript driver for ScyllaDB. Pre-release stage. 🧪🔧</h4>
</div>


## ⚠️ Disclaimer ⚠️

This repository and the associated npm package are currently in a 🐣 pre-release state and are being used for testing 🧪 purposes. They are subject to change without notice 📝. Eventually, they will be moved to the **ExpressoTS** organization under the `scylladb-driver` package name. Users are encouraged to use this driver with caution ❗ and not in production environments until the official release under the ExpressoTS organization.


## 🚀 Getting Started 🚀

These instructions will get you a copy of the project up and running 🏃 on your local machine for development and testing purposes.
Expand Down
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

/* auto-generated by NAPI-RS */

export const enum Compression {
None = 0,
Lz4 = 1,
Snappy = 2
}
export interface ClusterConfig {
nodes: Array<string>
compression?: Compression
defaultExecutionProfile?: ExecutionProfile
}
export const enum Consistency {
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,9 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { Consistency, Cluster, ScyllaSession, Uuid } = nativeBinding
const { Compression, Consistency, Cluster, ScyllaSession, Uuid } = nativeBinding

module.exports.Compression = Compression
module.exports.Consistency = Consistency
module.exports.Cluster = Cluster
module.exports.ScyllaSession = ScyllaSession
Expand Down
7 changes: 0 additions & 7 deletions src/cluster/cluster_config.rs

This file was deleted.

18 changes: 18 additions & 0 deletions src/cluster/cluster_config/compression.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use napi::bindgen_prelude::*;

#[napi]
pub enum Compression {
None,
Lz4,
Snappy,
}

impl From<Compression> for Option<scylla::transport::Compression> {
fn from(value: Compression) -> Self {
match value {
Compression::None => None,
Compression::Lz4 => Some(scylla::transport::Compression::Lz4),
Compression::Snappy => Some(scylla::transport::Compression::Snappy),
}
}
}
12 changes: 12 additions & 0 deletions src/cluster/cluster_config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::cluster::{
cluster_config::compression::Compression, execution_profile::ExecutionProfile,
};

pub mod compression;

#[napi(object)]
pub struct ClusterConfig {
pub nodes: Vec<String>,
pub compression: Option<Compression>,
pub default_execution_profile: Option<ExecutionProfile>,
}
12 changes: 11 additions & 1 deletion src/cluster/scylla_cluster.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use napi::Either;

use crate::{
cluster::{cluster_config::ClusterConfig, execution_profile::ExecutionProfile},
cluster::{
cluster_config::{compression::Compression, ClusterConfig},
execution_profile::ExecutionProfile,
},
session::scylla_session::ScyllaSession,
};

#[napi(js_name = "Cluster")]
struct ScyllaCluster {
uri: String,
compression: Option<Compression>,
default_execution_profile: Option<ExecutionProfile>,
}

Expand All @@ -33,13 +37,15 @@ impl ScyllaCluster {
pub fn new(cluster_config: ClusterConfig) -> Self {
let ClusterConfig {
nodes,
compression,
default_execution_profile,
} = cluster_config;

let uri = nodes.get(0).expect("at least one node is required");

Self {
uri: uri.to_string(),
compression,
default_execution_profile,
}
}
Expand Down Expand Up @@ -88,6 +94,10 @@ impl ScyllaCluster {
builder = builder.default_execution_profile_handle(default_execution_profile.into_handle());
}

if let Some(compression) = self.compression {
builder = builder.compression(compression.into());
}

Ok(ScyllaSession::new(builder.build().await.unwrap()))
}
}

0 comments on commit 019902a

Please sign in to comment.