Catyã®ãã¼ã¿ãã¼ã¹ããã¯ã¨ã³ãã®åè£ã¨ãã¦MongoDBãæ¤è¨ãã¦ãã¾ããMongoDBã®ã¯ã¨ãªè¨èªããç¾å¨Catyã§å®è£ ãã¦ããã¯ã¨ãªè¨èªã¨ãããã«ä¼¼ã¦ãããã§ç¬ã£ã¦ãã¾ãã¾ãããåãã¢ã¤ãã£ã¢ã«åºã¥ããæ§æãã»ã¨ãã©åãã§ããæ¯è¼ãã¦ã¿ã㨠-- 身è´å±ãªè©ä¾¡ããããã¾ããã -- Catyã¯ã¨ãªè¨èªã®ã»ãããããããã¨æãã¾ãã
Catyã§ã¯ãJSONãã¼ã¿ãä¿åãã貯èµåº«ããJSONã¹ãã¬ã¼ã¸ãã¨èº«ãèããªãå¼ã³æ¹ããã¦ãã¾ããä»ã¾ã§ç´¹ä»ãããã¨ããªãã£ãã®ã§ãããJSONã¹ãã¬ã¼ã¸ã¸ã®ã¯ã¨ãªï¼åãåããï¼è¨èªãåå¨ãã¾ããJSONã¹ãã¬ã¼ã¸ã¨ã¯ã¨ãªè¨èªã®è¨è¨ã¨å®è£ ã¯ãå ¨é¨Kuwataããã«ãããã®ã§ãããã¤ã®éã«ãåºæ¥ã¦ãã¾ããã
ç¾æç¹ã§ã®JSONã¹ãã¬ã¼ã¸ã¯ãããã¯ã¨ã³ãã«SQLiteã使ã£ã¦ãã¾ããJSONãã¼ã¿æ§é ã¨RDBçãªãã¼ã¿ã¢ãã«ã«ã¯ã»ãã³ãã£ãã¯ã®ã£ããããããããå®è£ ãç ©éã«ãªããããã©ã¼ãã³ã¹ãã¹ã±ã¼ã©ããªãã£ã«æ¸å¿µãããã¾ããããã§ãããã¯ã¨ã³ãããCouchDBã¨ãMongoDBã®ãããªããã¥ã¡ã³ãæåãã¼ã¿ãã¼ã¹ã«ç½®ãæãããã®ã§ãã
ããã¯ã¨ã³ããç½®ãæãã¦ããç¾å¨ã®ã¯ã¨ãªè¨èªã¯ãã®ã¾ã¾ä½¿ãç¶ããã¤ããã§ãããã®ã¯ã¨ãªè¨èªã¯ã¨ã¦ã使ãåæãããããé«ãæ´åæ§ãæã£ã¦ãã¾ããã¯ã¨ãªè¨èªã®å ·ä½çãªæ§æã¯å°ã風å¤ããã§ããããã§ã¯ãå ·ä½çãªæ§æããã¯é¢ãã¦ãæ½è±¡çã»è«ççãªã¬ãã«ã§ã¯ã¨ãªè¨èªãç´¹ä»ãã¾ããï¼å ·ä½çãªæ§æã¯ä½ç¨®é¡ããã£ã¦ãããã¨æãã¾ããï¼
å 容ï¼
- æºåãã»ãã®å°ã
- ã©ã ãå¼ã®ãã¨ãã»ãã®å°ã
- JSONãã¼ã¿ã®ãã¨ãã»ãã®å°ã
- äºé
é¢ä¿ã«ããæ¡ä»¶
- çå·
- æ°å¤ã®å¤§å°æ¯è¼
- æååã®ãããã³ã°
- æå±ï¼åã®å¤å®ï¼
- è«ççµåå
- é åã®æ¡ä»¶
- ãªãã¸ã§ã¯ãã®æ¡ä»¶
- ANYã¨UNDEFINED
- é åã«é¢ããå ¨ç§°å½é¡ã¨åå¨å½é¡
- ã¾ã¨ã
æºåãã»ãã®å°ã
ã©ã ãå¼ã®ãã¨ãã»ãã®å°ã
ä¾ãã°ãä¸çå·ã®è¨å·ãâ§ãã¯ã2å¤æ°ã§çå½å¤ãè¿ãé¢æ°ã¨èãããã¨ãã§ãã¾ãããã®ãã¨ãããããªã¨è¡¨ãããã«ã次ã®ãããªæ¸ãæ¹ããã¾ãã
- λ(x, y).(xâ§y)
λï¼ã©ã ãï¼ã®ç´å¾ã«å¼æ°ã¨ãªãå¤æ°ã並ã¹ãããªãªãã®å¾ã«å¤æ°ãå«ãå¼ãæ¸ãã®ã§ããï¼ã©ã ãå¼ã«é¢ãã¦ã¯ãJavaScriptã§å¦ã¶ã»ããã°ã©ãã®ããã®ã©ã ãè¨ç®ããåç §ãï¼ä¸çå·ãâ§ãã®å³å´ãå®æ°ã«ãã¦ãã¾ãã¨ãå¼æ°å¤æ°ã¯1åã«ãªãã¾ãã
- λ(x).(xâ§10)
å¼æ°å¤æ°ï¼ã©ã ãã§æç¸ãããå¤æ°ï¼ã1åãããªãã©ã ãå¼ããç¡åå¤æ°ã¨ãã¦ã_ãï¼ã¢ã³ãã¹ã³ã¢ï¼ã使ã£ã¦æ¬¡ã®ããã«è¡¨ããã¨ã«ãã¾ãã
- (_â§10)
ããããå ãã¢ã³ãã¹ã³ã¢ãå«ãå¼ã¯1å¤æ°ã®ã©ã ãå¼ã§ããããã®å¤ã¯çå½å¤ï¼boolean valueï¼ã§ããã¨ç´æãã¾ãã
JSONãã¼ã¿ã®ãã¨ãã»ãã®å°ã
JSONãã¼ã¿ã¯ãã¹ã«ã©ã¼ãã¼ã¿ã¾ãã¯è¤åãã¼ã¿ã§ããã¹ã«ã©ã¼ãã¼ã¿ã¨è¤åãã¼ã¿ã«ã¯æ¬¡ã®ç¨®é¡ãããã¾ãã
- ã¹ã«ã©ã¼ï¼æ°å¤å numberï¼ 1, -2, 3.14 ãªã©
- ã¹ã«ã©ã¼ï¼æååå stringï¼ "hello", "", "æªå±±" ãªã©
- ã¹ã«ã©ã¼ï¼çå½å¤å booleanï¼ true, false
- ã¹ã«ã©ã¼ï¼ãã«å nullï¼ nullï¼ãªãã©ã«ï¼
- è¤åï¼é åå arrayï¼ [1, "hello"], [] ãªã©
- è¤åï¼ãªãã¸ã§ã¯ãå objectï¼ {"x": 1, "y": -3.5, "color":"red"}, {} ãªã©
é åã®æåãé ç®ï¼itemï¼ã¨å¼ã³ããªãã¸ã§ã¯ãã®æåãããããã£ï¼propertyï¼ã¨å¼ã³ã¾ãããã®ä»ã«ãè¦ç´ ï¼elementï¼ãã¡ã³ãï¼memberï¼ããã£ã¼ã«ãï¼fieldï¼ããã¼ï¼keyï¼ãªã©ã®è¨èã使ããããã¨ãããã¾ãã
ã²ã¨ã¤ã®JSONã¹ãã¬ã¼ã¸ã¯ãããã¤ãã®JSONã³ã¬ã¯ã·ã§ã³*1ãå«ã¿ã¾ããã³ã¬ã¯ã·ã§ã³ã¯ãJSONãªãã¸ã§ã¯ããã¼ã¿ã®éåã§ãã
ã¯ã¨ãªè¨èªã¯ãJSONãã¼ã¿ã«é¢ããæ¡ä»¶ãè¨è¿°ããããã®è¨èªã§ããè¨è¿°ãããæ¡ä»¶ãæºããJSONãã¼ã¿ãã³ã¬ã¯ã·ã§ã³ããæ½åºããã¾ããå¥ãªè¨ãæ¹ãããã¨ãã³ã¬ã¯ã·ã§ã³ã®é¨åéåã {xâSomeCollection | ï¼xã«é¢ããæ¡ä»¶ï¼} ã¨æ¸ãããã¨ãã«ãï¼xã«é¢ããæ¡ä»¶ï¼ã表ç¾ããè¨èªãã¯ã¨ãªè¨èªã§ãã
äºé é¢ä¿ã«ããæ¡ä»¶
äºé é¢ä¿ã¯2ã¤ã®å¤æ°ãæã¡ã¾ããããã®çæ¹ãå®æ°ã«ãã¦æ¡ä»¶ãå®ç¾©ã§ãã¾ãã
çå·
次ã¯ãçå·ã使ã£ãæ¡ä»¶ã®ä¾ã§ãã
- (_ = 1)
- (_ = -3.5)
- (_ = "hello")
- (_ = [1, 2, 3])
- (_ = {"x": 1, "y":-3.5})
ãã以ä¸èª¬æãããã¨ã¯ãªãã§ãã
æ°å¤ã®å¤§å°æ¯è¼
使ããé¢ä¿è¨å·ï¼æ¯è¼æ¼ç®åï¼ã¯ãï¼ãâ§ãï¼ã⦠ã®4ã¤ã§ããç¡åå¤æ° _ ã«å ¥ãå¤ã¯æ°å¤ï¼numberï¼ã«éãã¾ãã
- (_ ï¼ 0)
- (_ ⧠3.14)
- (_ ï¼ 256)
- (_ ⦠-20)
ãããã説æãããã¨ããªãã§ãã
æååã®ãããã³ã°
ãããã³ã°ã®æ¼ç®åã¨ãã¦ã=~ ã使ããã¨ã«ãã¾ãã=~ ã®å³å´ã«ã¯æ£è¦è¡¨ç¾ãªãã©ã«ããSQLã®LIKEãã¿ã¼ã³ãæ¸ããã¨ãã¾ããæ£è¦è¡¨ç¾ã¯ã¹ã©ãã·ã¥ã§å²ã¿ãLIKEãã¿ã¼ã³ã¯ã·ã³ã°ã«ã¯ã©ã¼ãã§å²ããã¨ã«ãã¾ã*2ãç¡åå¤æ° _ ã«å ¥ãå¤ã¯æååï¼stringï¼ã«éãã¾ãã
- (_ =~ /^h.*o$/)
- (_ =~ 'h%o')
- (_ =~ /^....$/)
- (_ =~ '____')
æå±ï¼åã®å¤å®ï¼
éåã¸ã®æå±ã â ã§è¡¨ãã¾ããã¾ããåã®ååãéåã®æå³ã§ã使ãã¾ããxâstring ã¯ããxã¯æååã®éåã«æå±ãããã¾ãã¯ãxã®åã¯stringã§ããããæå³ãã¾ãã以ä¸ã®ä¾ã®integerã¯ãnumberã®ãªãã§ç¹ã«æ´æ°ã§ããåã§ãã
- (_ â string)
- (_ â boolean)
- (_ â integer)
ç¹å¥ãªåã¨ãã¦anyããããä»»æã®JSONãã¼ã¿ãanyã«æå±ãã¾ãã次ã®æ¡ä»¶ã¯å¸¸ã«çã¨ãªãã¾ãã
- (_ â any)
è«ççµåå
è«ççµååï¼logical connectivesï¼ã¯ãã決ã¾ãã® AND, OR, NOT ã®3ã¤ã§ããè«ççµååã¯ãåºæ¬çãªæ¡ä»¶ããè¤éãªæ¡ä»¶ãçµã¿ç«ã¦ãéã«ä½¿ãã¾ãã
- (_ ⧠0) AND (_ ⦠10) â¦â¦ 0以ä¸10以ä¸
- NOT (_ ⧠0) â¦â¦ (_ ï¼ 0) ã¨åã
- (_ = true) OR (_ = false) â¦â¦ (_ â boolean) ã¨åã
- (_ â integer) AND (_ ï¼ 0) AND (_ ⦠2) â¦â¦ (_ = 1) OR (_ = 2) ã¨åã
- NOT ((_ = 0) OR (_ = "")) â¦â¦ 0ã§ããªã空æååã§ããªã
é åã®æ¡ä»¶
é åã«é¢ããæ¡ä»¶ã¯ãé ç®ã«å¯¾ããæ¡ä»¶ã並ã¹ã¦è¨è¿°ãã¾ãã
- [(_ ⧠0), (_ â string)]
ãã®ä¾ã¯ãæåã®é ç®ã0以ä¸ã®æ°å¤ã§ã次ã®è¦ç´ ãæååã§ãããã¨ã示ãã¾ãã3çªç®ä»¥éï¼é åã¤ã³ããã¯ã¹ã¯2以ä¸ï¼ã®è¦ç´ ã«é¢ãã¦ã¯ä½ã®æ¡ä»¶ã課ãã¦ã¾ããã次ã®é åã¤ã³ã¹ã¿ã³ã¹ã¯ãã®æ¡ä»¶ãæºããã¾ãã
- [1, "hello"]
- [3.14, "", true]
- [0, "hello", "json", "strage", "query"]
æåã®é ç®ã«ä½ã®æ¡ä»¶ã課ããã2çªç®ã ãã«æ¡ä»¶ãä»ãããã¨ãã¯æ¬¡ã®ããã«ãã¾ãã
- [(_ â any), (_ â string)]
(_ â any) ã¯å¸¸ã«çãªã®ã§ããä½ã®æ¡ä»¶ã課ããªããã¨ãã«ä½¿ãã¾ãã
æ«å°¾ã«ç¶ãããã®ä»ã®é ç®ãã«é¢ããæ¡ä»¶ï¼ç¹°ãè¿ãé©ç¨ãããï¼ã¯ãæ¡ä»¶å ¨ä½ã«ã*ããä»ãã¾ãã
- [(_ ⧠0), (_ â string)*]
ããã¯ãæåã®é ç®ã0以ä¸ã®æ°å¤ã§ã2çªç®ä»¥éã®é ç®ãããã°æååã§ãããã¨ãè¦æ±ãã¾ãã
ãªãã¸ã§ã¯ãã®æ¡ä»¶
ããããã£ã«é¢ããæ¡ä»¶ã¯ãããããã£å¤ã«é¢ããæ¡ä»¶ã®åã«ããããã£åãä»ããã ãã§ãã
- ï¼ããããã£åï¼ : ï¼ããããã£å¤ã«é¢ããæ¡ä»¶ï¼
ããããã£åã¯ããã«ã¯ã©ã¼ããããæååãªãã©ã«ã§ããä¾ãã°ã"age" : (_ ⧠20) ãããããã£ã«é¢ããæ¡ä»¶ã並ã¹ã¦ãã¬ã¤ã¹ï¼æ³¢æ¬å¼§ï¼ã§å²ãã°ãªãã¸ã§ã¯ãã«é¢ããæ¡ä»¶ã§ãã
- {"x" : (_ ⧠0), "y" : (_ ⧠0)} â¦â¦ 第1象éã®ç¹
- {"gender" : (_ = "M"), "age" : (_ ⧠20)} â¦â¦ æ人ç·å
ããã®ä»ã®ããããã£ãã«é¢ããæ¡ä»¶ã¯ãããããã£åãã*ãã¨ãã¾ãã
- {"x" : (_ = 0), * : (_ ⧠0)} â¦â¦ x座æ¨ã¯0ããã®ä»ã¯è² ã§ãªã
ANYã¨UNDEFINED
(_ â any) ã®ç¥è¨ã¨ãã¦ANYã使ãã¾ããANYã¯ããã ãã§æ¡ä»¶ã§ãããã©ããªãã¼ã¿ã§ãANYæ¡ä»¶ãæºããã¾ãã
(_ â undefined) ã®ç¥è¨ã¨ãã¦UNDEFINEDã使ãã¾ããundefinedåã¯JSONã«ã¯åå¨ãã¾ãããããJavaScriptã«ã¯ undfinedåããããå®ç¾©ããã¦ãªãé
åé
ç®ï¼ãªãã¸ã§ã¯ãããããã£ã«ã¢ã¯ã»ã¹ããã¨undefinedåã®å¤ãè¿ã£ã¦ãã¾ãã
ANY, UNDEFINEDã¯æ¬¡ã®ããã«ä½¿ãã¾ãã
- [(_ ⧠0), ANY, UNDEFINED]
- {"age" : (_ ⧠20), "maritalPartner" : UNDEFINED}
- {"x" : (_ â number), "y" : (_ â number), * : UNDEFINED}
æåã®ä¾ã§ã¯ãé åã®3çªç®ãUNDEFINDãªã®ã§ããã®é åã®é·ãã2ã§ãããã¨ãè¦æ±ãã¦ãã¾ãã第2é ç®ï¼é åã¤ã³ããã¯ã¹ã¯1ï¼ã¯å¿ é ã§ããANYã«ã¯undefinedåãå«ã¾ãã¦ãªãã®ã§ããundefineã§ãããã¨æå®ãããªããANY OR UNDEFINED ã¨ãã¾ãã
2çªç®ã®ä¾ã¯ãæ人ã§æªå©ããæå³ãã¾ãããã ããé å¶è ï¼"maritalPartner"ï¼ã®ããããã£ãåå¨ããªãã¨ãã¯æªå©ã¨ã¿ãªãã¨ããåæãããã¾ãã
3çªç®ã®ä¾ã¯ã"x", "y" 以å¤ã®ããããã£ãåºç¾ããªããã¨ãè¦æ±ãã¦ãã¾ããã*ãããã®ä»ã®ããããã£ãæå³ãããããUNDEFINEDãã¤ã¾ãåå¨ããªããã¨ã§ãã
ï¼æ¡ä»¶ï¼ OR UNDEFINED ã¯ãã使ãã®ã§ãï¼æ¡ä»¶ï¼? ã¨ç¥è¨ãããã¨ã«ãã¾ããé·ãã1ã¾ãã¯2ã§ããé åã¯æ¬¡ã®æ¡ä»¶ã§è¨è¿°ã§ãã¾ãã
- [ANY, ANY?, UNDEFINED]
é åã«é¢ããå ¨ç§°å½é¡ã¨åå¨å½é¡
éåSã®ãã¹ã¦ã®è¦ç´ ã«å¯¾ãã¦å½é¡Pãæç«ãããã¨ããâxâS.P(x) ã¨æ¸ãã¾ããéåSã®å°ãªãã¨ã1ã¤ã®è¦ç´ ã«å¯¾ãã¦å½é¡Pãæç«ãããã¨ããâxâS.P(x) ã¨æ¸ãã¾ããéåã®ä»£ããã«é åã使ããã¨ã«ãã¦ãåãè¨å·âãâã使ã£ã¦æ¡ä»¶ãè¨è¿°ãããã¨ã«ãã¾ãããã
âï¼æ¡ä»¶ï¼ ã¯ãé åã®ãã¹ã¦ã®é ç®ãï¼æ¡ä»¶ï¼ãæºãããã¨ã表ãã¾ããâï¼æ¡ä»¶ï¼ ã¯ãé åã®å°ãªãã¨ã1ã¤ã®é ç®ãï¼æ¡ä»¶ï¼ãæºãããã¨ã表ãã¾ãã
- â(_ ⧠0) â¦â¦ é åã®ãã¹ã¦ã®é ç®ãè² ã§ãªãæ°å¤
- â(_ = 0) â¦â¦ é åã®å°ãªãã¨ã1ã¤ã®é ç®ã0
è«ççµååã¨çµã¿åããã¦ã¿ã¾ãã
- â((_ ⧠0) OR (_ = "unbounded")) â¦â¦ é åã®ãã¹ã¦ã®é ç®ããè² ã§ãªãæ°å¤ã"unbounded"ã
- â(NOT (_ = 0)) â¦â¦ é åã®å°ãªãã¨ã1ã¤ã®é ç®ãã0ã§ã¯ãªãã
ã¾ã¨ã
以ä¸ããCatyã¯ã¨ãªè¨èªã®æ½è±¡çã»è«ççãªæ§é ã§ãã
çå·ã¨ãã¹ã«ã©ã¼ãã¼ã¿ã®é åä¸ã§å®ç¾©ãããåé åºæ¬è¿°èª*3ããã¨ã«ãã¦ãè¿°èªè«çã®è«çæ¼ç®ï¼AND, OR, NOT, â, âï¼ã使ã£ã¦çµã¿ç«ã¦ãè«çå¼ã®ä½ç³»ã«ãªã£ã¦ãã¾ããJSONã®è¤åãã¼ã¿æ§ææ³ã§ããé åæ§æã¨ãªãã¸ã§ã¯ãæ§æã«ã対å¿ãã¦ãã¾ãã
ããã¯ãJSONã¤ã³ã¹ã¿ã³ã¹ãããªãéåãå®ç¾©ããè«çå¼ã®è¨èªã¨ãªã£ã¦ãããä¸ããããéåï¼ã³ã¬ã¯ã·ã§ã³ï¼ãçµãè¾¼ãç®çã«ï¼ã¤ã¾ãã¯ã¨ãªè¨èªã¨ãã¦ï¼ä½¿ãã¾ããå¤å ¸è«çã¨ãã¼ã¿åã«é¢ããæ¨è«ããã®ã¾ã¾ç´ ç´ã«ä½¿ããç¹ãã¡ãªããã ã¨æãã¾ãã
*1:Catyã§ã¯ã³ã¬ã¯ã·ã§ã³ã§ã¯ãªããã¼ãã«ã¨å¼ãã§ã¾ããããMongoDBã®ç¨èªãã³ã¬ã¯ã·ã§ã³ãã®ã»ãããµããããã¨æãã®ã§ãä»å¾ã¯ãã³ã¬ã¯ã·ã§ã³ãã«ããããã¨ã
*2:LIKEãã¿ã¼ã³ã®å ´åãã¨ã¹ã±ã¼ãæåãå¯å¤ãªã®ãå°ã£ãã¨ããã§ãã
*3:åºæ¬è¿°èªãå ¨åé¢æ°ã¨ã¯éãã¾ãããè«çå¼ã«å¯¾ããã¢ãã«ã¯ãä¸è¬ã«é¨åé¢æ°ã¨ãªãã¾ãã