-
Notifications
You must be signed in to change notification settings - Fork 2
/
sqlite_config.rb
44 lines (38 loc) · 1.06 KB
/
sqlite_config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'sqlite3'
# Open a database
$db = SQLite3::Database.new 'data/people_ads.db'
# Create tables
$db.execute <<-SQL
create table IF NOT EXISTS people
(id INTEGER PRIMARY KEY AUTOINCREMENT,
name varchar(30),
email varchar(30))
SQL
$db.execute <<-SQL
create table IF NOT EXISTS ads
(id INTEGER PRIMARY KEY AUTOINCREMENT,
person_id integer,
ad_text varchar(256),
counts integer,
date datetime DEFAULT current_timestamp,
category varchar(256)
);
SQL
$db.execute <<-SQL
create table IF NOT EXISTS ads_for_rental
(id INTEGER PRIMARY KEY AUTOINCREMENT,
person_id integer,
ad_text varchar(256),
counts integer,
date datetime DEFAULT current_timestamp,
category varchar(256)
);
SQL
$db.execute <<-SQL
CREATE UNIQUE INDEX IF NOT EXISTS ADS_AD_TEXT_INDEX ON ads (ad_text);
SQL
$db.execute <<-SQL
create table IF NOT EXISTS phones
(no varchar(11) PRIMARY KEY,
person_id integer)
SQL