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

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. 

主站蜘蛛池模板: 民乐县| 宁南县| 乌拉特后旗| 平湖市| 江山市| 营口市| 松桃| 寿宁县| 清原| 富民县| 宿州市| 高密市| 治县。| 凉城县| 安乡县| 汉中市| 崇礼县| 合江县| 易门县| 乐都县| 高碑店市| 临沭县| 梁平县| 北碚区| 大足县| 高唐县| 从江县| 随州市| 应用必备| 屯留县| 桃园县| 醴陵市| 永丰县| 即墨市| 吉安市| 南涧| 宜兴市| 沭阳县| 静海县| 云林县| 鲁山县|