Tham chiếu ML ứng dụng - Cơ sở dữ liệu
Thuộc tính "cơ sở dữ liệu"
Thuộc tính "cơ sở dữ liệu" định nghĩa cơ sở dữ liệu là nguồn dữ liệu. Nó có các thuộc tính phụ sau:
Element | Description |
---|---|
"connection" | The name of a database connection |
"execute" | Array of SQL statements to be executed before data retrieval (optional) |
"keyfield" | The key field for the main table (optional) |
"maintable" | The main table for this application (optional) |
"orderby" | A fixed SQL orderby clause for the application (optional) |
"sql" | The SQL statement for retrieving data |
Dữ liệu từ cơ sở dữ liệu
Mô hình này tìm nạp các bản ghi chứa Khách hàng, Thành phố và Quốc gia từ bảng Khách hàng trong cơ sở dữ liệu SQL:
Thí dụ
{
"database": {
"connection": "mysql",
"sql" :
"SELECT CustomerName, City, Country FROM Customers",
"orderby" : "CustomerName"
}
}
Giới hạn bộ lọc
Để cho phép người dùng lọc dữ liệu, bạn có thể thêm thông tin bộ lọc vào mô hình:
"filteritems" : [
{"item" : "CustomerName", "label" : "Customer"},
{"item" : "City"},
{"item" : "Country"}]
Hạn chế sắp xếp
Để cho phép người dùng sắp xếp dữ liệu, bạn có thể thêm thông tin sắp xếp vào mô hình:
"sortitems" : [
{"item" : "CustomerName", "label" : "Customer"},
{"item" : "City"},
{"item" : "Country"}]
Cập nhật các hạn chế
Để cho phép người dùng cập nhật dữ liệu, bạn có thể đưa thông tin cập nhật vào mô hình:
Thí dụ
"updateItems" : [
{"item" : "CustomerName"},
{"item" : "Address"},
{"item" : "PostalCode"},
{"item" : "City"},
{"item" : "Country"}]
Theo mặc định, AppML sẽ cho phép bạn lọc, sắp xếp hoặc cập nhật dữ liệu, chỉ dữ liệu được chỉ định trong mô hình.
Kết nối cơ sở dữ liệu
Các kết nối cơ sở dữ liệu được định nghĩa trong appml_config.php :
appml_config.php
<?php echo("Access Forbidden");exit();?>
{
"dateformat" : "yyyy-mm-dd",
"databases": [
{
"connection" : "mysql",
"host"
: "127.0.0.1:3306",
"dbname" : "Northwind",
"username"
: "myUserId",
"password" : "myPassword"
},
{
"connection" : "googleDB",
"host" :
"192.168.1.1:3306",
"dbname" : "Northwind",
"username"
: "myUserId",
"password" : "myPassword"
},
{
"connection" : "amazonDB",
"host" :
"mydbinstance.amazon.com:3306",
"dbname" : "Northwind",
"username" : "myUserId",
"password" : "myPassword"
},
{
"connection" : "azureDB",
"host" :
"azure.cloudapp.net",
"dbname" : "Northwind",
"username" :
"myUserId",
"password" : "myPassword"
}
]
}
Tệp cấu hình có thể chứa nhiều kết nối cơ sở dữ liệu.
Tạo cơ sở dữ liệu
Vì AppML cho phép bạn thực thi các câu lệnh SQL trước khi khởi động ứng dụng, bạn có thể sử dụng điều này để tạo cơ sở dữ liệu nếu cần:
Mô hình
{
"database" : {
"connection" : "myCDs",
"execute" : [
"DROP
TABLE IF EXISTS CD_Catalog",
"CREATE TABLE IF NOT EXISTS CD_Catalog (CDID
INT NOT NULL AUTO_INCREMENT,PRIMARY KEY (CDID),Title NVARCHAR(255),Artist NVARCHAR(255),Country NVARCHAR(255),Price
NUMBER)"
]
}}
Hoàn hảo để tạo mẫu nhanh!