This file contains hidden or 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
$ python hs.py | |
{'user_name': 'tistaharahap', 'user_id': '1', 'user_email': '[email protected]', 'created': '2016-09-06 15:00:00'} |
This file contains hidden or 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
from pyhs import Manager | |
def get_user_by_id(hs, user_id): | |
pass | |
def main(): | |
hs = Manager() # Assuming that Handlersocket is available at 127.0.0.1 |
This file contains hidden or 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
$ pip install -r requirements.txt | |
Collecting python-handler-socket (from -r deps (line 1)) | |
Downloading python-handler-socket-0.2.4.tar.gz | |
Building wheels for collected packages: python-handler-socket | |
Running setup.py bdist_wheel for python-handler-socket ... done | |
Stored in directory: /Users/tista/Library/Caches/pip/wheels/48/7c/46/ee1c1e3dabc22527c8780ac7ae3ca7ba03a66e6720d5d1f481 | |
Successfully built python-handler-socket | |
Installing collected packages: python-handler-socket | |
Successfully installed python-handler-socket-0.2.4 |
This file contains hidden or 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
python-handler-socket |
This file contains hidden or 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
CREATE TABLE user ( | |
user_id INT UNSIGNED PRIMARY KEY, | |
user_name VARCHAR(50), | |
user_email VARCHAR(255), | |
created DATETIME | |
) ENGINE=InnoDB; |
This file contains hidden or 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
It may not seem like it, but there’s a lot of information packed into those 10 columns! The columns returned by the query are: | |
id – a sequential identifier for each SELECT within the query (for when you have nested subqueries) | |
select_type – the type of SELECT query. Possible values are: | |
SIMPLE – the query is a simple SELECT query without any subqueries or UNIONs | |
PRIMARY – the SELECT is in the outermost query in a JOIN | |
DERIVED – the SELECT is part of a subquery within a FROM clause | |
SUBQUERY – the first SELECT in a subquery | |
DEPENDENT SUBQUERY – a subquery which is dependent upon on outer query | |
UNCACHEABLE SUBQUERY – a subquery which is not cacheable (there are certain conditions for a query to be cacheable) |
This file contains hidden or 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
MariaDB [fun]> EXPLAIN SELECT * FROM users WHERE first_name = 'Martin' AND last_name = 'David'; | |
+------+-------------+-------+------+----------------------+----------------------+---------+-------------+------+--------------------------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+------+-------------+-------+------+----------------------+----------------------+---------+-------------+------+--------------------------+ | |
| 1 | SIMPLE | users | ref | first_and_last_names | first_and_last_names | 106 | const,const | 1 | Using where; Using index | | |
+------+-------------+-------+------+----------------------+----------------------+---------+-------------+------+--------------------------+ | |
1 row in set (0.00 sec) |
This file contains hidden or 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
MariaDB [fun]> CREATE INDEX first_and_last_names ON users (first_name, last_name); | |
Query OK, 0 rows affected (0.01 sec) | |
Records: 0 Duplicates: 0 Warnings: 0 |
This file contains hidden or 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
MariaDB [fun]> EXPLAIN SELECT * FROM users WHERE first_name = 'Martin' AND last_name = 'David'; | |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------+ | |
| 1 | SIMPLE | users | ALL | NULL | NULL | NULL | NULL | 10 | Using where | | |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------+ | |
1 row in set (0.00 sec) |
This file contains hidden or 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
MariaDB [fun]> SELECT * FROM names WHERE first_name = 'Martin' AND last_name = 'David'; | |
+----+------------+-----------+ | |
| id | first_name | last_name | | |
+----+------------+-----------+ | |
| 10 | Martin | David | | |
+----+------------+-----------+ | |
1 row in set (0.01 sec) |