Felhasználói eszközök

Eszközök a webhelyen


oktatas:web:back-end_framework:sails:adatbazis

Különbségek

A kiválasztott változat és az aktuális verzió közötti különbségek a következők.

Összehasonlító nézet linkje

Előző változat mindkét oldalonElőző változat
oktatas:web:back-end_framework:sails:adatbazis [2023/05/13 10:31] – [MySQL] adminoktatas:web:back-end_framework:sails:adatbazis [2025/08/01 11:08] (aktuális) – eltávolítva admin
Sor 1: Sor 1:
-[[oktatas:web:back-end_framework:sails|< Sails]] 
- 
-====== Sails - Adatbázis ====== 
- 
-  * **Szerző:** Sallai András 
-  * Copyright (c) Sallai András, 2023 
-  * Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]] 
-  * Web: https://szit.hu 
- 
-===== Model generálása ===== 
- 
- 
-  sails generate api employee 
- 
- 
-===== MySQL ===== 
- 
- 
-  npm install sails-mysql 
- 
- 
-  * config/datastores.js 
- 
-<code javascript config/datastores.js> 
- 
-default: { 
-  adapter: 'sails-mysql', 
-  user: 'root', 
-  password: '', 
-  port: '3306', 
-  host: 'localhost', 
-  database: 'valami' 
-}, 
- 
-</code> 
- 
- 
-<code javascript api/models/Employee.js> 
-module.exports = { 
- 
-  attributes: { 
-    name: { type: 'string', required: true}, 
-    city: { type: 'string', required: false}, 
-    salary: { type: 'number', required: false}     
-  }, 
- 
-}; 
-</code> 
- 
-Az id automatikus növekménye a következő helyen van beállítva: 
- 
-   * config/models.js 
- 
-<code javascript> 
-    id: { type: 'number', autoIncrement: true, }, 
-</code> 
- 
-==== Törlés és frissítés ==== 
- 
-Dolgozó törlésnél, frissítésénél, az azonosító lehet URL paramétere, vagy JSON adatok között az id attribútum. 
- 
- 
-===== SQLite ===== 
- 
-  npm install sails-sqlite3 
- 
-<code javascript config/datastores.js> 
-const sqlite3 = require('sqlite3'); 
- 
-//... 
- 
-default: { 
-  adapter: 'sails-sqlite3', 
-  filename: 'database.db', 
-  mode: sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, 
-  verbose: false 
-}, 
-</code> 
- 
- 
-<code javascript config/models.js> 
-//... 
-id: { type: 'number', autoIncrement: true, }, 
-</code> 
- 
-<code javascript api/models/Employee.js> 
-module.exports = { 
- 
-  attributes: { 
-    name: { type: 'string', required: true}, 
-    city: { type: 'string', required: false}, 
-    salary: { type: 'number', required: false}     
-  }, 
- 
-}; 
-</code> 
- 
-===== MongoDB ===== 
- 
-A keresőbe: 
- 
-  * mongodb community download 
- 
- 
-Lehetséges GUI kliens: 
-  * MongoDB Compass 
- 
- 
-Adapter telepítése: 
-  npm i sails-mongo 
- 
- 
-A models.js beállítása: 
- 
-<code javascript> 
-id: { type: 'string', columnName: '_id' }, 
-</code> 
- 
- 
-<code javascript config/datastores.js> 
- 
-default: { 
-    adapter: 'sails-mongo', 
-    url: 'mongodb://127.0.0.1:27017/dbname' 
-}, 
- 
-</code> 
- 
- 
-Adatbázis URL: janos felhasználóval, titok jelszóval, zold adatbázisnévvel: 
- 
-  mongodb://janos:titok@localost:27017/zold 
- 
- 
-<code javascript api/models/Employee.js> 
-module.exports = { 
- 
-  attributes: { 
-    name: { type: 'string', required: true}, 
-    city: { type: 'string', required: false}, 
-    salary: { type: 'number', required: false}     
-  }, 
- 
-}; 
-</code> 
  
oktatas/web/back-end_framework/sails/adatbazis.1683966706.txt.gz · Utolsó módosítás: 2023/05/13 10:31 szerkesztette: admin