App ML Verwysing - Databasisse
Die "databasis" Eiendom
Die "databasis"-eienskap definieer 'n databasis as die databron. Dit het die volgende sub-eienskappe:
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 uit 'n databasis
Hierdie model haal rekords wat kliënt, stad en land bevat van 'n klanttabel in 'n SQL-databasis:
Voorbeeld
{
"database": {
"connection": "mysql",
"sql" :
"SELECT CustomerName, City, Country FROM Customers",
"orderby" : "CustomerName"
}
}
Filterbeperkings
Om gebruikers toe te laat om data te filtreer, kan jy filterinligting by die model voeg:
"filteritems" : [
{"item" : "CustomerName", "label" : "Customer"},
{"item" : "City"},
{"item" : "Country"}]
Sorteerbeperkings
Om gebruikers toe te laat om data te sorteer, kan jy sorteerinligting by die model voeg:
"sortitems" : [
{"item" : "CustomerName", "label" : "Customer"},
{"item" : "City"},
{"item" : "Country"}]
Dateer beperkings op
Om gebruikers toe te laat om data op te dateer, kan jy opdateringsinligting by die model insluit:
Voorbeeld
"updateItems" : [
{"item" : "CustomerName"},
{"item" : "Address"},
{"item" : "PostalCode"},
{"item" : "City"},
{"item" : "Country"}]
By verstek sal AppML jou toelaat om data te filter, sorteer of op te dateer, net dit word in die model gespesifiseer.
Databasisverbindings
Databasisverbindings word in appml_config.php gedefinieer :
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"
}
]
}
Die konfigurasielêer kan baie databasisverbindings bevat.
Die skep van databasisse
Aangesien AppML jou toelaat om SQL-stellings uit te voer voordat die toepassing begin word, kan jy dit gebruik om 'n databasis te skep indien nodig:
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)"
]
}}
Ideaal vir vinnige prototipering!