Last active
June 18, 2019 07:40
-
-
Save filinivan/7fa80c3bb15382258156a081272e391d to your computer and use it in GitHub Desktop.
Работа с базой данных
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1 - Установить соединение с базой данных. (set :database, "sqlite3:barbershop.db") | |
| 2 - Создаем модель (Класс) class Barber < ActiveRecord::Base end | |
| 3 - Создаем файл миграции утилитой rake ( rake db:create_migration NAME=name_of_migration) | |
| 4 - Редактируем файл миграции | |
| create_table :clients do |t| | |
| t.text :name | |
| t.text :phone | |
| t.text :datestamp | |
| t.text :barber | |
| t.timestamps | |
| end | |
| 5 - Выполняем миграцию ( rake db:migrate ) | |
| Так же должны быть установлены Гемы и создан Rakefile (В нем прописывается что слушать) | |
| Изминения при миграции ---------------------------------- | |
| class AddColumns < ActiveRecord::Migration[5.2] | |
| def change | |
| add_column :words, :phraze, :text // в какой таблице, какая строка, какой тип | |
| add_column :words, :level, :text | |
| end | |
| end | |
| -------- Работа с утилитой sqlite | |
| sqlite3 base.db - подключение к базе данных | |
| .tables - отобразить список таблиц в бд | |
| .exit - выход из утилиты | |
| select * from Orders; - отобразить всё из таблицы orders | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment