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

Saving to the database

The data collector application currently writes to the filesystem. While this is useful for archiving, it makes it difficult and slow to access and query any sort of analysis or display.

Note

If you are not experienced with databases, here is a very rapid introduction! Databases are collections of data in a structured form. These are accessed and managed via a database management system. You may have heard of SQL Server, MySQL, Hadoop or Oracle.

Databases are typically accessed using a language called SQL to read and write records from the database. Data is usually organized into tables, and each table is made up of records. Each table has a set columns defined as data types—it is similar to variables in a programming language. SQL is strong on sorting, grouping, and working with sets of data.

SQL can be stored in the database in a number of forms, with the most common being a stored procedure that can add/remove and update data, and perform some processing.

Connecting to a database almost always requires a login and may be on a remote computer. This is sometimes referred to as a connection string. It behaves much like a network connection.

Installing a database system

There are numerous database systems available and you probably already have your favorite one! For the purposes of this book, the database used will be PostgreSQL as it is free, open source, and available for all the major operating systems. Also it is one of the easiest databases to install, so we can spend more time writing Dart.

PostgreSQL is a powerful, open-source, object-relational database system with a 15-year heritage behind it.

It is a first-class product and is used by big names in industry and government, such as Yahoo and the United Nations. It complies strongly with SQL language standards and can cope with database tables up to a maximum size of 32 terabytes.

PostgreSQL can be downloaded from http://www.postgresql.org/ for Mac, Linux, and Windows, and is available via most Linux distribution package managers. Also on the PostgreSQL download page, there are numerous virtual machine images available that just need to be downloaded and turned on.

The examples for this book assume that the database installation is the same machine that the software is run from. Adjusting the connection string will allow connection to remote machines.

Using PostgreSQL from Dart

The package postgresql provides a very capable PostgreSQL database driver to use from the Dart program. It is a third-party package that is well regarded, and has had contributions from the Dart team.

The project for this section is called QuakeMonitorDB and the fetching is identical to the filesystem version.

主站蜘蛛池模板: 林芝县| 东莞市| 衡阳县| 金门县| 平利县| 凌源市| 梁平县| 平定县| 鹤峰县| 平昌县| 德令哈市| 新蔡县| 丹寨县| 鄂托克前旗| 祥云县| 奈曼旗| 阆中市| 噶尔县| 探索| 克东县| 宁津县| 景泰县| 娱乐| 明星| 阿克| 剑河县| 万盛区| 丰城市| 扎兰屯市| 肃宁县| 宜君县| 蒙山县| 宾阳县| 漳浦县| 武功县| 大田县| 门源| 谷城县| 志丹县| 嘉定区| 进贤县|