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

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.

主站蜘蛛池模板: 高台县| 香河县| 赣州市| 浪卡子县| 奇台县| 哈巴河县| 洪洞县| 渝中区| 都昌县| 榕江县| 金秀| 大安市| 雅安市| 广州市| 长宁区| 洛宁县| 无为县| 嘉善县| 武宣县| 大渡口区| 天祝| 乡城县| 延长县| 大余县| 全南县| 杭锦后旗| 易门县| 临武县| 山阳县| 桂阳县| 黄平县| 舒城县| 仙居县| 九寨沟县| 车致| 彰武县| 威海市| 玛多县| 正蓝旗| 永寿县| 德江县|