Skip to content

Commit

Permalink
Merge pull request #2 from nebula-contrib/add-cross-212
Browse files Browse the repository at this point in the history
update readme and add cross build for scala 2.12
  • Loading branch information
jxnu-liguobin committed Sep 8, 2023
2 parents b7bd4fa + bdaec42 commit a20988f
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 135 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/dependency-graph.yml
@@ -0,0 +1,12 @@
name: Update Dependency Graph
on:
push:
branches:
- master
jobs:
dependency-graph:
name: Update Dependency Graph
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: scalacenter/sbt-dependency-submission@v2
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -8,4 +8,5 @@ target/
data/
logs/
.idea/
.bsp/
.bsp/
sdap.sbt
29 changes: 18 additions & 11 deletions README.md
Expand Up @@ -6,11 +6,11 @@ ZIO Client for NebulaGraph
![CI][Badge-CI] [![Nexus (Snapshots)][Badge-Snapshots]][Link-Snapshots] [![Sonatype Nexus (Releases)][Badge-Release]][Link-Release]


[Badge-CI]: https://github.com/hjfruit/zio-nebula/actions/workflows/scala.yml/badge.svg
[Badge-CI]: https://github.com/nebula-contrib/zio-nebula/actions/workflows/scala.yml/badge.svg
[Badge-Snapshots]: https://img.shields.io/nexus/s/io.github.jxnu-liguobin/zio-nebula_3?server=https%3A%2F%2Foss.sonatype.org
[Link-Snapshots]: https://oss.sonatype.org/content/repositories/snapshots/io/github/jxnu-liguobin/zio-nebula_3/
[Link-Release]: https://index.scala-lang.org/hjfruit/zio-nebula/zio-nebula
[Badge-Release]: https://index.scala-lang.org/hjfruit/zio-nebula/zio-nebula/latest-by-scala-version.svg?platform=jvm
[Link-Release]: https://index.scala-lang.org/nebula-contrib/zio-nebula/zio-nebula
[Badge-Release]: https://index.scala-lang.org/nebula-contrib/zio-nebula/zio-nebula/latest-by-scala-version.svg?platform=jvm


[zio-nebula](https://github.com/hjfruit/zio-nebula) is a simple wrapper around [nebula-java](https://github.com/vesoft-inc/nebula-java/) for easier integration into Scala, ZIO applications.
Expand All @@ -19,15 +19,20 @@ ZIO Client for NebulaGraph

## Dependency

Support Scala 2.13 or Scala 3:
Support Scala 3, Scala 2.13 and Scala 2.12:
```scala
libraryDependencies += "io.github.jxnu-liguobin" %% "zio-nebula" % <latest version>
```

## Environment
## Version


There are the version correspondence between zio-nebula and nebula-java:

| zio | zio-nebula | nebula-java |
|:-----:|:----------:|:-----------:|
| 2.0.x | 0.0.x | 3.6.0 |

- zio 2.0.13
- nebula-java 3.6.0

## Example

Expand Down Expand Up @@ -88,11 +93,13 @@ object NebulaSessionClientMain extends ZIOAppDefault {

## Configuration

- key `graph` for `NebulaSessionClient`
- key `meta` for `NebulaMetaClient`
- key `storage` for `NebulaStorageClient`
- key `pool` for `NebulaClient`
Introduction for configuring keys:
- key `graph` for `NebulaSessionClient`
- key `meta` for `NebulaMetaClient`
- key `storage` for `NebulaStorageClient`
- key `pool` for `NebulaClient`

Sample Configuration:
```hocon
{
graph = {
Expand Down
34 changes: 23 additions & 11 deletions build.sbt
@@ -1,14 +1,17 @@
val zioVersion = "2.0.13"
val scala3Version = "3.2.2"
val scala2Version = "2.13.10"
val scala3_Version = "3.3.1"
val scala2_13Version = "2.13.10"
val scala2_12Version = "2.12.16"
val zioConfigVersion = "4.0.0-RC16"
val nebulaClientVersion = "3.6.0"
val logbackVersion = "1.4.5"

val supportCrossVersionList = Seq(scala3_Version, scala2_13Version, scala2_12Version)

inThisBuild(
List(
scalaVersion := scala3Version,
homepage := Some(url("https://github.com/hjfruit/zio-nebula")),
scalaVersion := supportCrossVersionList.head,
homepage := Some(url("https://github.com/nebula-contrib/zio-nebula")),
licenses := List("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
organization := "io.github.jxnu-liguobin",
organizationName := "梦境迷离",
Expand All @@ -26,27 +29,33 @@ inThisBuild(
addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck")

val _zioTests = Seq(
"dev.zio" %% "zio-test-magnolia" % zioVersion,
"dev.zio" %% "zio-test" % zioVersion,
"dev.zio" %% "zio-test-sbt" % zioVersion
)

lazy val core = project
.in(file("core"))
.settings(
name := "zio-nebula",
crossScalaVersions := Seq(scala3Version, scala2Version),
name := "zio-nebula",
crossScalaVersions := supportCrossVersionList,
libraryDependencies ++= Seq(
"com.vesoft" % "client" % nebulaClientVersion,
"dev.zio" %% "zio-config-typesafe" % zioConfigVersion,
"dev.zio" %% "zio-config-magnolia" % zioConfigVersion,
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-test" % zioVersion % Test,
"ch.qos.logback" % "logback-classic" % logbackVersion % Test
),
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
) ++ _zioTests.map(_ % Test),
Test / parallelExecution := false,
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
)

lazy val examples = project
.in(file("examples"))
.settings(
publish / skip := true,
crossScalaVersions := Seq(scala3Version, scala2Version),
crossScalaVersions := supportCrossVersionList,
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % logbackVersion
)
Expand All @@ -56,7 +65,10 @@ lazy val examples = project
lazy val `zio-nebula` = project
.in(file("."))
.settings(
publish / skip := true
crossScalaVersions := Nil,
publish / skip := true,
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
libraryDependencies ++= _zioTests.map(_ % Test)
)
.aggregate(
core,
Expand Down
52 changes: 26 additions & 26 deletions core/src/main/scala/zio/nebula/NebulaResultSet.scala
Expand Up @@ -15,61 +15,61 @@ import com.vesoft.nebula.graph.PlanDescription
* 梦境迷离
* @version 1.0,2023/8/29
*/
final class NebulaResultSet(resultSet: ResultSet) {
final class NebulaResultSet(underlying: ResultSet) {

import NebulaResultSet._

def isSucceeded: Boolean = resultSet.isSucceeded
def isSucceeded: Boolean = underlying.isSucceeded

def isEmpty: Boolean = resultSet.isEmpty
def isEmpty: Boolean = underlying.isEmpty

def errorCode: Int = resultSet.getErrorCode
def errorCode: Int = underlying.getErrorCode

def spaceName: String = resultSet.getSpaceName
def spaceName: String = underlying.getSpaceName

def errorMessage: String = resultSet.getErrorMessage
def errorMessage: String = underlying.getErrorMessage

def comment: String = resultSet.getComment
def comment: String = underlying.getComment

def latency: Long = resultSet.getLatency
def latency: Long = underlying.getLatency

def planDesc: PlanDescription = resultSet.getPlanDesc
def planDesc: PlanDescription = underlying.getPlanDesc

def keys: List[String] = resultSet.getColumnNames.asScala.toList
def keys: List[String] = underlying.getColumnNames.asScala.toList

def columnNames: List[String] = resultSet.getColumnNames.asScala.toList
def columnNames: List[String] = underlying.getColumnNames.asScala.toList

def rowsSize: Int = resultSet.rowsSize()
def rowsSize: Int = underlying.rowsSize()

def rowValues(index: Int): NebulaRecord = new NebulaRecord(resultSet.rowValues(index))
def rowValues(index: Int): NebulaRecord = new NebulaRecord(underlying.rowValues(index))

def colValues(columnName: String): List[ValueWrapper] = resultSet.colValues(columnName).asScala.toList
def colValues(columnName: String): List[ValueWrapper] = underlying.colValues(columnName).asScala.toList

def rows: List[Row] = resultSet.getRows.asScala.toList
def rows: List[Row] = underlying.getRows.asScala.toList

override def toString: String = resultSet.toString
override def toString: String = underlying.toString
}

object NebulaResultSet {

final class NebulaRecord(record: Record) extends Iterable[ValueWrapper] {
final class NebulaRecord(private val underlying: Record) extends Iterable[ValueWrapper] {

override def iterator: Iterator[ValueWrapper] = record.iterator().asScala
override def iterator: Iterator[ValueWrapper] = underlying.iterator().asScala

override def foreach[U](f: ValueWrapper => U): Unit = record.forEach((t: ValueWrapper) => f.apply(t))
override def foreach[U](f: ValueWrapper => U): Unit = underlying.forEach((t: ValueWrapper) => f.apply(t))

override def toString(): String = record.toString
override def toString(): String = underlying.toString

def spliterator: Spliterator[ValueWrapper] = record.spliterator
def spliterator: Spliterator[ValueWrapper] = underlying.spliterator

def get(index: Int): ValueWrapper = record.get(index)
def get(index: Int): ValueWrapper = underlying.get(index)

def get(columnName: String): ValueWrapper = record.get(columnName)
def get(columnName: String): ValueWrapper = underlying.get(columnName)

def values: util.List[ValueWrapper] = record.values()
def values: util.List[ValueWrapper] = underlying.values()

override def size: Int = record.size()
override def size: Int = underlying.size()

def contains(columnName: String): Boolean = record.contains(columnName)
def contains(columnName: String): Boolean = underlying.contains(columnName)
}
}
4 changes: 2 additions & 2 deletions core/src/main/scala/zio/nebula/NebulaSessionClient.scala
Expand Up @@ -45,12 +45,12 @@ trait NebulaSessionClient {
/**
* get the number of all Session
*/
def getSessionNums: Task[Int]
def sessionNum: Task[Int]

/**
* get the number of idle Session
*/
def getIdleSessionNums: Task[Int]
def idleSessionNum: Task[Int]
}

object NebulaSessionClient {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/zio/nebula/NebulaSessionClientLive.scala
Expand Up @@ -14,16 +14,16 @@ private[nebula] final class NebulaSessionClientLive(underlying: SessionPool) ext
override def execute(stmt: String): Task[NebulaResultSet] =
ZIO.attempt(new NebulaResultSet(underlying.execute(stmt)))

override def getIdleSessionNums: Task[Int] = ZIO.attempt(underlying.getIdleSessionNums)
override def idleSessionNum: Task[Int] = ZIO.attempt(underlying.getIdleSessionNums)

override def getSessionNums: Task[Int] = ZIO.attempt(underlying.getSessionNums)
override def sessionNum: Task[Int] = ZIO.attempt(underlying.getSessionNums)

override def isActive: Task[Boolean] = ZIO.attempt(underlying.isActive)

override def isClosed: Task[Boolean] = ZIO.attempt(underlying.isClosed())

override def close(): Task[Unit] = ZIO.attempt(underlying.close())

override def init(): Task[Boolean] = ZIO.attemptBlocking(underlying.init())
override def init(): Task[Boolean] = ZIO.attempt(underlying.init())

}
16 changes: 8 additions & 8 deletions core/src/main/scala/zio/nebula/meta/NebulaMetaClient.scala
Expand Up @@ -18,21 +18,21 @@ trait NebulaMetaClient {

def close(): Task[Unit]

def getSpaceId(spaceName: String): Task[Int]
def spaceId(spaceName: String): Task[Int]

def getSpace(spaceName: String): Task[SpaceItem]
def space(spaceName: String): Task[SpaceItem]

def getTagId(spaceName: String, tagName: String): Task[Int]
def tagId(spaceName: String, tagName: String): Task[Int]

def getTag(spaceName: String, tagName: String): Task[TagItem]
def tag(spaceName: String, tagName: String): Task[TagItem]

def getEdgeType(spaceName: String, edgeName: String): Task[Int]
def edgeType(spaceName: String, edgeName: String): Task[Int]

def getLeader(spaceName: String, part: Int): Task[NebulaHostAddress]
def leader(spaceName: String, part: Int): Task[NebulaHostAddress]

def getSpaceParts(spaceName: String): Task[List[Int]]
def spaceParts(spaceName: String): Task[List[Int]]

def getPartsAlloc(spaceName: String): Task[Map[Int, List[NebulaHostAddress]]]
def partsAlloc(spaceName: String): Task[Map[Int, List[NebulaHostAddress]]]

def listHosts: Task[Set[NebulaHostAddress]]
}
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/scala/zio/nebula/meta/NebulaMetaClientLive.scala
Expand Up @@ -17,23 +17,23 @@ private[nebula] final class NebulaMetaClientLive(underlying: MetaManager) extend

override def close(): Task[Unit] = ZIO.attempt(underlying.close())

override def getSpaceId(spaceName: String): Task[Int] = ZIO.attempt(underlying.getSpaceId(spaceName))
override def spaceId(spaceName: String): Task[Int] = ZIO.attempt(underlying.getSpaceId(spaceName))

override def getSpace(spaceName: String): Task[SpaceItem] = ZIO.attempt(underlying.getSpace(spaceName))
override def space(spaceName: String): Task[SpaceItem] = ZIO.attempt(underlying.getSpace(spaceName))

override def getTagId(spaceName: String, tagName: String): Task[Int] =
override def tagId(spaceName: String, tagName: String): Task[Int] =
ZIO.attempt(underlying.getTagId(spaceName, tagName))

override def getTag(spaceName: String, tagName: String): Task[TagItem] =
override def tag(spaceName: String, tagName: String): Task[TagItem] =
ZIO.attempt(underlying.getTag(spaceName, tagName))

override def getEdgeType(spaceName: String, edgeName: String): Task[Int] =
override def edgeType(spaceName: String, edgeName: String): Task[Int] =
ZIO.attempt(underlying.getEdgeType(spaceName, edgeName))

override def getLeader(spaceName: String, part: Int): Task[NebulaHostAddress] =
override def leader(spaceName: String, part: Int): Task[NebulaHostAddress] =
ZIO.attempt(underlying.getLeader(spaceName, part)).map(h => NebulaHostAddress(h.getHost, h.getPort))

override def getSpaceParts(spaceName: String): Task[List[Int]] =
override def spaceParts(spaceName: String): Task[List[Int]] =
ZIO.attempt(
underlying
.getSpaceParts(spaceName)
Expand All @@ -44,7 +44,7 @@ private[nebula] final class NebulaMetaClientLive(underlying: MetaManager) extend
.toList
)

override def getPartsAlloc(spaceName: String): Task[Map[Int, List[NebulaHostAddress]]] =
override def partsAlloc(spaceName: String): Task[Map[Int, List[NebulaHostAddress]]] =
ZIO.attempt(
underlying
.getPartsAlloc(spaceName)
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/zio/nebula/net/NebulaClient.scala
Expand Up @@ -18,13 +18,13 @@ trait NebulaClient {

def close(): Task[Unit]

def getSession: ZIO[Scope & NebulaSessionPoolConfig, Throwable, NebulaSession]
def openSession(): ZIO[Scope & NebulaSessionPoolConfig, Throwable, NebulaSession]

def getActiveConnNum: Task[Int]
def activeConnNum: Task[Int]

def getIdleConnNum: Task[Int]
def idleConnNum: Task[Int]

def getWaitersNum: Task[Int]
def waitersNum: Task[Int]

}

Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/zio/nebula/net/NebulaClientLive.scala
Expand Up @@ -22,15 +22,15 @@ private[nebula] final class NebulaClientLive(underlying: NebulaPl) extends Nebul
config <- ZIO.service[NebulaPoolConfig]
status <-
ZIO.serviceWithZIO[NebulaSessionPoolConfig](sessionConfig =>
ZIO.attemptBlocking(
ZIO.attempt(
underlying.init(sessionConfig.address.map(d => new HostAddress(d.host, d.port)).asJava, config.toJava)
)
)
} yield status

def close(): Task[Unit] = ZIO.attempt(underlying.close())

def getSession: ZIO[Scope & NebulaSessionPoolConfig, Throwable, NebulaSession] =
def openSession(): ZIO[Scope & NebulaSessionPoolConfig, Throwable, NebulaSession] =
for {
sessionConfig <- ZIO.service[NebulaSessionPoolConfig]
session <-
Expand All @@ -47,10 +47,10 @@ private[nebula] final class NebulaClientLive(underlying: NebulaPl) extends Nebul
)(_.close().onError(e => ZIO.logErrorCause(e)).ignoreLogged)
} yield session

def getActiveConnNum: Task[Int] = ZIO.attempt(underlying.getActiveConnNum)
def activeConnNum: Task[Int] = ZIO.attempt(underlying.getActiveConnNum)

def getIdleConnNum: Task[Int] = ZIO.attempt(underlying.getIdleConnNum)
def idleConnNum: Task[Int] = ZIO.attempt(underlying.getIdleConnNum)

def getWaitersNum: Task[Int] = ZIO.attempt(underlying.getWaitersNum)
def waitersNum: Task[Int] = ZIO.attempt(underlying.getWaitersNum)

}

0 comments on commit a20988f

Please sign in to comment.