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

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. 

主站蜘蛛池模板: 城步| 林西县| 太湖县| 常德市| 东丽区| 澄江县| 滨海县| 桃园市| 信丰县| 板桥市| 抚顺县| 南丹县| 获嘉县| 洛扎县| 屏东县| 洛浦县| 巨鹿县| 台州市| 高青县| 始兴县| 安龙县| 墨竹工卡县| 右玉县| 定襄县| 宝坻区| 个旧市| 广汉市| 三原县| 佛冈县| 上思县| 横山县| 中江县| 泉州市| 米泉市| 茌平县| 循化| 屏东县| 施秉县| 南康市| 崇礼县| 钟祥市|