Referensi App ML - Basis Data
Properti "database"
Properti "database" mendefinisikan database sebagai sumber data. Ini memiliki sub properti berikut:
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 |
Data Dari Basis Data
Model ini mengambil rekaman yang berisi Pelanggan, Kota, dan Negara dari tabel Pelanggan dalam database SQL:
Contoh
{
"database": {
"connection": "mysql",
"sql" :
"SELECT CustomerName, City, Country FROM Customers",
"orderby" : "CustomerName"
}
}
Batasan Filter
Untuk mengizinkan pengguna memfilter data, Anda dapat menambahkan informasi filter ke model:
"filteritems" : [
{"item" : "CustomerName", "label" : "Customer"},
{"item" : "City"},
{"item" : "Country"}]
Batasan penyortiran
Untuk mengizinkan pengguna mengurutkan data, Anda dapat menambahkan informasi pengurutan ke model:
"sortitems" : [
{"item" : "CustomerName", "label" : "Customer"},
{"item" : "City"},
{"item" : "Country"}]
Perbarui Batasan
Untuk mengizinkan pengguna memperbarui data, Anda dapat menyertakan informasi pembaruan dalam model:
Contoh
"updateItems" : [
{"item" : "CustomerName"},
{"item" : "Address"},
{"item" : "PostalCode"},
{"item" : "City"},
{"item" : "Country"}]
Secara default, AppML akan memungkinkan Anda memfilter, mengurutkan, atau memperbarui data, hanya itu yang ditentukan dalam model.
Koneksi Basis Data
Koneksi database didefinisikan di 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"
}
]
}
File konfigurasi dapat berisi banyak koneksi database.
Membuat Database
Karena AppML memungkinkan Anda untuk mengeksekusi pernyataan SQL sebelum aplikasi dimulai, Anda dapat menggunakan ini untuk membuat database jika diperlukan:
Model
{
"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)"
]
}}
Sempurna untuk pembuatan prototipe cepat!