Slick-pgSlick 的 PostgreSQL 扩展
Slick-pg 是一些针对 PostgreSQL 的 Slick 扩展,用于支持 PostgreSQL 的(特有)类型及/或相关函数。如果你对使用 Slick 来开发基于 PostgreSQL 的程序感兴趣,那么你会发现 slick-pg 非常有用。
有了它,我们就可以在 Scala/Slick 项目里自由的使用那些 PostgreSQL 特有的、因而 Slick 肯定不会内置支持的那些数据类型及其操作/函数来构造 SQL 查询了:
import MyPostgresDriver.simple._ class TestTable(tag: Tag) extends Table[Test](tag, Some("xxx"), "Test") { def id = column[Long]("id", O.AutoInc, O.PrimaryKey) def during = column[Range[Timestamp]]("during") def location = column[Point]("location") def text = column[String]("text", O.DBType("varchar(4000)")) def props = column[Map[String,String]]("props_hstore") def tags = column[List[String]]("tags_arr") def * = (id, during, location, text, props, tags) <> (Test.tupled, Test.unapply) } object tests extends TableQuery(new TestTable(_)) { /// def byId(ids: Long*) = tests.filter(_.id inSetBind ids).map(t => t) // will generate sql like: select * from test where tags && ? def byTag(tags: String*) = tests.filter(_.tags @& tags.toList.bind).map(t => t) // will generate sql like: select * from test where during && ? def byTsRange(tsRange: Range[Timestamp]) = tests.filter(_.during @& tsRange.bind).map(t => t) // will generate sql like: select * from test where case(props -> ? as [T]) == ? def byProperty[T](key: String, value: T) = tests.filter(_.props.>>[T](key.bind) === value.bind).map(t => t) // will generate sql like: select * from test where ST_DWithin(location, ?, ?) def byDistance(point: Point, distance: Int) = tests.filter(r => r.location.dWithin(point.bind, distance.bind)).map(t => t) // will generate sql like: // select id, text, ts_rank(to_tsvector(text), to_tsquery(?)) // from test // where to_tsvector(text) @@ to_tsquery(?) // order by ts_rank(to_tsvector(text), to_tsquery(?)) def search(queryStr: String) = tests.filter(tsVector(_.text) @@ tsQuery(queryStr.bind)) .map(r => (r.id, r.text, tsRank(tsVector(r.text), tsQuery(queryStr.bind)))) .sortBy(_._3) } ...
目前支持的 PostgreSQL 类型有:
-
ARRAY
-
JSON
-
Date/Time
-
Enum
-
Range
-
HStore
-
LTree
- Inet/MacAddr
-
text Search
-
postgis Geometry
目前支持的 PostgreSQL 特性有:
- inherits
- Composite type (basic)
- aggregate functions
- window functions
评论
Apache AGE提供图数据库功能的 PostgreSQL 扩展
ApacheAGE是一个PostgreSQL扩展,提供图数据库功能。AGE是AGraphExtension的首字母缩写,其灵感来自Bitnine的PostgreSQL10分支AgensGraph,后者
Apache AGE提供图数据库功能的 PostgreSQL 扩展
0
Apache AGE提供图数据库功能的 PostgreSQL 扩展
Apache AGE 是一个 PostgreSQL 扩展,提供图数据库功能。AGE 是 A Grap
Apache AGE提供图数据库功能的 PostgreSQL 扩展
0
pgxr使用 Rust 开发 PostgreSQL 扩展函数
pgxr —— 使用 Rust 开发 PostgreSQL 扩展函数(存储过程)pgxr 是一个 R
pgxr使用 Rust 开发 PostgreSQL 扩展函数
0
pgxr使用 Rust 开发 PostgreSQL 扩展函数
pgxr——使用Rust开发PostgreSQL扩展函数(存储过程)pgxr是一个Rust的crate库,可以实现用Rust语言来编写PostgreSQL的扩展函数(相当于存储过程)。代码示例:#[m
pgxr使用 Rust 开发 PostgreSQL 扩展函数
0
PyGreSQLPython的PostgreSQL模块
PyGreSQL 是一个开源的 Python 模块用来访问 PostgreSQL 数据库,嵌入 Po
PyGreSQLPython的PostgreSQL模块
0
KuiBaDBRust 重写的 PostgreSQL
KuiBaDB 是使用 Asynchronous Rust 重写的 PostgreSQL,专注于 O
KuiBaDBRust 重写的 PostgreSQL
0
PyGreSQLPython的PostgreSQL模块
PyGreSQL是一个开源的Python模块用来访问PostgreSQL数据库,嵌入PostgreSQL查询库可方便在Python代码中使用PostgreSQL强大的功能。
PyGreSQLPython的PostgreSQL模块
0
KuiBaDBRust 重写的 PostgreSQL
KuiBaDB是使用AsynchronousRust重写的PostgreSQL,专注于OLAP分析。KuiBaDB构建在kbio和tokio之上,只使用tokio的 'rt-multi-thread'
KuiBaDBRust 重写的 PostgreSQL
0