官术网_书友最值得收藏!

Putting it all together

You should now know enough to build an example that does what we described at the beginning of the chapter. We have learned the following:

  • How to read a TOML file to parameterize the program
  • How to load the data regarding products and sales into memory, specified in a JSON file and in an XML file
  • How to store all of this data in three places: a SQLite DB file, a PostgreSQL database, and a Redis key-value store

The source code of the complete example is found in the transformer project. To run it, open its folder and type in cargo run ../data/config.toml. If everything is successful, it will recreate and populate the SQLite database contained in the data/sales.db file, the PostgreSQL database, which can be accessed from localhost on port 5432 and is named Rust2018, and the Redis store, which can be accessed from localhost. Then, it will query the SQLite and PostgreSQL databases for the number of rows in their tables, and it will print the following:

SQLite #Products=4. 
SQLite #Sales=5.
PostgreSQL #Products=4.
PostgreSQL #Sales=5.

So, we have now seen a rather broad example of data manipulation. 

主站蜘蛛池模板: 彰武县| 阿拉善左旗| 公安县| 措勤县| 大关县| 始兴县| 石台县| 桃园县| 东安县| 丰县| 古浪县| 江永县| 庄浪县| 牡丹江市| 华坪县| 体育| 神农架林区| 长泰县| 扬中市| 张家界市| 金湖县| 旺苍县| 阿克| 武义县| 福泉市| 信阳市| 九龙县| 屯昌县| 罗平县| 思茅市| 高青县| 平江县| 马鞍山市| 福清市| 通榆县| 镇沅| 凤山县| 大英县| 霍山县| 乌拉特中旗| 辽宁省|