Skip to content

Commit

Permalink
rename some slick function names for hstore
Browse files Browse the repository at this point in the history
  • Loading branch information
tminglei committed Sep 15, 2013
1 parent edbf478 commit 099c8fa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ trait PgHStoreSupport { driver: PostgresDriver =>
object HStoreLibrary {
val On = new SqlOperator("->")
val Exist = new SqlFunction("exist")
// val ExistAll = new SqlOperator("?&") //can't support, because there exists '?' conflict
// val ExistAny = new SqlOperator("?|") //can't support, because there exists '?' conflict
// val ExistAll = new SqlOperator("?&") //can't support, '?' conflict with jdbc '?'
// val ExistAny = new SqlOperator("?|") //can't support, '?' conflict with jdbc '?'
val Defined = new SqlFunction("defined")
val Contains = new SqlOperator("@>")
val ContainedBy = new SqlOperator("<@")
Expand Down Expand Up @@ -65,13 +65,13 @@ trait PgHStoreSupport { driver: PostgresDriver =>
def @+[P2, R](c2: Column[P2])(implicit om: o#arg[Map[String, String], P2]#to[Map[String, String], R]) = {
om(HStoreLibrary.Concatenate.column[Map[String, String]](n, Node(c2)))
}
def @-[P2, R](c2: Column[P2])(implicit om: o#arg[String, P2]#to[Map[String, String], R]) = {
def @-[P2, R](c2: Column[P2])(implicit om: o#arg[Map[String, String], P2]#to[Map[String, String], R]) = {
om(HStoreLibrary.Delete.column[Map[String, String]](n, Node(c2)))
}
def --[P2, R](c2: Column[P2])(implicit om: o#arg[List[String], P2]#to[Map[String, String], R]) = {
om(HStoreLibrary.Delete.column[Map[String, String]](n, Node(c2)))
}
def -/[P2, R](c2: Column[P2])(implicit om: o#arg[Map[String, String], P2]#to[Map[String, String], R]) = {
def -/[P2, R](c2: Column[P2])(implicit om: o#arg[String, P2]#to[Map[String, String], R]) = {
om(HStoreLibrary.Delete.column[Map[String, String]](n, Node(c2)))
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/com/github/tminglei.slickpg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ Supported data type's operators/functions
| >> | cast(hstore->k as T) | get value of type T for key | cast('a=>3,b=>y'::hstore ->'a' as int) | 3 |
| ?? | exist | does hstore contain key? | exist('a=>1','a') | t |
| ?& | defined | does hstore contain non-NULL value for key? | defined('a=>NULL','a') | f |
| can't support because of '?' | ?& | does hstore contain all the keys? | 'a=>1,b=>2'::hstore ?& ARRAY['a','b'] | t |
| can't support because of '?' | ?&#124; | does hstore contain any the keys? | 'a=>1,b=>2'::hstore ?&#124; ARRAY['b','c'] | t |
| '?' conflict with jdbc '?' | ?& | does hstore contain all the keys? | 'a=>1,b=>2'::hstore ?& ARRAY['a','b'] | t |
| '?' conflict with jdbc '?' | ?&#124; | does hstore contain any the keys? | 'a=>1,b=>2'::hstore ?&#124; ARRAY['b','c'] | t |
| @> | @> | does left operand contain right? | 'a=>b, b=>1, c=>NULL'::hstore @> 'b=>1' | t |
| <@: | <@ | is left operand contained in right? | 'a=>c'::hstore <@ 'a=>b, b=>1, c=>NULL' | f |
| @+ | &#124;&#124; | concatenate hstores | 'a=>b, c=>d'::hstore &#124;&#124; 'c=>x, d=>q'::hstore | "a"=>"b", "c"=>"x", "d"=>"q" |
| @- | - | delete key from left operand | 'a=>1, b=>2, c=>3'::hstore - 'b' | "a"=>"1", "c"=>"3" |
| @- | - | delete matching pairs from left operand | 'a=>1, b=>2, c=>3'::hstore - 'a=>4, b=>2'::hstore | "a"=>"1", "c"=>"3" |
| -- | - | delete keys from left operand | 'a=>1, b=>2, c=>3'::hstore - ARRAY['a','b'] | "c"=>"3" |
| -/ | - | delete matching pairs from left operand | 'a=>1, b=>2, c=>3'::hstore - 'a=>4, b=>2'::hstore | "a"=>"1", "c"=>"3" |
| -/ | - | delete key from left operand | 'a=>1, b=>2, c=>3'::hstore - 'b' | "a"=>"1", "c"=>"3" |

#### Search
| Slick Operator/Function | PG Operator/Function | Description | Example | Result |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ class PgHStoreSupportTest {
println(s"'@+' sql = ${q5.selectStatement}")
assertEquals(Map("a"->"test", "c"->"105"), q5.first())

val q6 = HStoreTestTable.where(_.id === 37L).map(t => t.hstore @- "a".bind)
val q6 = HStoreTestTable.where(_.id === 37L).map(t => t.hstore @- Map("a"->"111", "c"->"105").bind)
println(s"'@-' sql = ${q6.selectStatement}")
assertEquals(Map("c"->"105"), q6.first())
assertEquals(Map("a"->null), q6.first())

val q7 = HStoreTestTable.where(_.id === 37L).map(t => t.hstore -- List("a").bind)
println(s"'--' sql = ${q7.selectStatement}")
assertEquals(Map("c"->"105"), q7.first())

val q8 = HStoreTestTable.where(_.id === 37L).map(t => t.hstore -/ Map("a"->"111", "c"->"105").bind)
val q8 = HStoreTestTable.where(_.id === 37L).map(t => t.hstore -/ "a".bind)
println(s"'-/' sql = ${q8.selectStatement}")
assertEquals(Map("a"->null), q8.first())
assertEquals(Map("c"->"105"), q8.first())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PgSearchSupportTest {

//-----------------------------------------------------------------------------

val testRec1 = TestBean(33L, "fat cats ate rats", "")
val testRec1 = TestBean(33L, "fat cat ate rat", "")
val testRec2 = TestBean(37L, "cat", "fat")

@Test
Expand Down

0 comments on commit 099c8fa

Please sign in to comment.