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

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. 

主站蜘蛛池模板: 儋州市| 秦安县| 大洼县| 长春市| 嘉禾县| 左权县| 广德县| 师宗县| 台中县| 黄平县| 郧西县| 长春市| 林州市| 潞城市| 固始县| 巴林右旗| 五台县| 宜兴市| 子长县| 宜兴市| 论坛| 剑阁县| 清徐县| 正安县| 怀化市| 儋州市| 黄梅县| 正阳县| 衡水市| 类乌齐县| 邯郸县| 东乌珠穆沁旗| 墨竹工卡县| 广州市| 玉屏| 驻马店市| 宝兴县| 杭锦后旗| 襄樊市| 封丘县| 安阳市|