Created
March 30, 2012 17:16
-
-
Save stevegury/2253056 to your computer and use it in GitHub Desktop.
Finagle MySQL codec in action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.twitter.finagle.mysql._ | |
import java.net.InetSocketAddress | |
val login = "stevegury" | |
val client = MySQLClient(new InetSocketAddress("localhost", 3306), login, password) | |
val query = for { | |
_ <- client.use("my_db") | |
res <- client.query("select * from my_table") | |
} yield res | |
query.get() | |
[info] Starting scala interpreter... | |
[info] | |
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> val password = <hidden> | |
password: java.lang.String = ... | |
scala> | |
scala> import com.twitter.finagle.mysql._ | |
import com.twitter.finagle.mysql._ | |
scala> import java.net.InetSocketAddress | |
import java.net.InetSocketAddress | |
scala> | |
scala> val login = "stevegury" | |
login: java.lang.String = stevegury | |
scala> val client = MySQLClient(new InetSocketAddress("localhost", 3306), login, password) | |
client: com.twitter.finagle.mysql.MySQLClient = com.twitter.finagle.mysql.MySQLClient@df20541 | |
scala> | |
scala> val query = for { | |
<- Decoding MySQL packet (n=0, size=74) | |
| _ 0A 35 2E 35 2E 32 30 00 07 00 00 00 25 3D 44 7A 5.5.20 %=Dz | |
5D 43 74 41 00 FF F7 21 02 00 0F 80 15 00 00 00 ]CtA ! | |
00 00 00 00 00 00 00 25 36 7D 36 32 3A 6A 29 2B %6}62:j)+ | |
3A 22 3A 00 6D 79 73 71 6C 5F 6E 61 74 69 76 65 :": mysql_native | |
5F 70 61 73 73 77 6F 72 64 00 _password | |
<- client.use("my_db") | |
-> Encoding LoginRequest | |
3F 00 00 01 85 A6 02 80 00 00 00 10 21 00 00 00 ? ! | |
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | |
00 00 00 00 73 74 65 76 65 67 75 72 79 00 14 19 stevegury | |
CD BA 33 C9 EC 34 A0 6A 8C 40 54 F8 DE 04 9E 76 3 4 j @T v | |
4C 18 E9 L | |
| res <- client.query("select * from my_table") | |
<- Decoding MySQL packet (n=2, size=7) | |
00 00 00 02 00 00 00 | |
| } yield res | |
-> Encoding Use(my_db) | |
06 00 00 00 02 6D 79 5F 64 62 my_db | |
<- Decoding MySQL packet (n=1, size=7) | |
00 00 00 02 00 00 00 | |
-> Encoding Query(select * from my_table) | |
17 00 00 00 03 73 65 6C 65 63 74 20 2A 20 66 72 select * fr | |
6F 6D 20 6D 79 5F 74 61 62 6C 65 om my_table | |
<- Decoding MySQL packet (n=1, size=1) | |
02 | |
query: com.twitter.util.Future[com.twitter.finagle.mysql.protocol.Result] = Promise@473975727(ivar=Ivar@1093196966(state=Waiting(List(),List())), cancelled=Ivar@1959493164(state=Waiting(List(<function1>),List()))) | |
scala> | |
scala> query.get() | |
<- Decoding MySQL packet (n=2, size=47) | |
03 64 65 66 05 6D 79 5F 64 62 08 6D 79 5F 74 61 def my_db my_ta | |
62 6C 65 08 6D 79 5F 74 61 62 6C 65 02 69 64 02 ble my_table id | |
69 64 0C 3F 00 0B 00 00 00 03 23 42 00 00 00 id ? #B | |
<- Decoding MySQL packet (n=3, size=51) | |
03 64 65 66 05 6D 79 5F 64 62 08 6D 79 5F 74 61 def my_db my_ta | |
62 6C 65 08 6D 79 5F 74 61 62 6C 65 04 6E 61 6D ble my_table nam | |
65 04 6E 61 6D 65 0C 21 00 60 00 00 00 FD 00 00 e name ! ` | |
00 00 00 | |
<- Decoding MySQL packet (n=4, size=5) | |
FE 00 00 22 00 " | |
<- Decoding MySQL packet (n=5, size=9) | |
01 31 06 66 6F 6F 62 61 72 1 foobar | |
<- Decoding MySQL packet (n=6, size=11) | |
01 32 08 74 6F 74 6F 31 32 33 34 2 toto1234 | |
<- Decoding MySQL packet (n=7, size=11) | |
01 33 08 73 64 66 6C 73 6E 64 66 3 sdflsndf | |
<- Decoding MySQL packet (n=8, size=15) | |
03 34 33 35 0A 73 64 66 6D 6E 62 73 6B 6A 62 435 sdfmnbskjb | |
<- Decoding MySQL packet (n=9, size=5) | |
FE 00 00 22 00 " | |
res0: com.twitter.finagle.mysql.protocol.Result = | |
id name | |
1 foobar | |
2 toto1234 | |
3 sdflsndf | |
435 sdfmnbskjb | |
scala> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment