-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirstRun.js
More file actions
76 lines (69 loc) · 1.93 KB
/
firstRun.js
File metadata and controls
76 lines (69 loc) · 1.93 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import * as FileSystem from 'expo-file-system';
import * as Localization from 'expo-localization';
import {db, TRACK_DIR} from './styleConst';
const CREATE_TABLE = `
PRAGMA foreign_keys = ON;
CREATE TABLE IF NOT EXISTS Playlists (
lst_name TEXT PRIMARY KEY,
);
CREATE TABLE IF NOT EXISTS Tracks (
track_name TEXT PRIMARY KEY,
);
CREATE TABLE IF NOT EXISTS Linking (
fk_lst_name TEXT,
fk_track_name TEXT,
PRIMARY KEY (fk_lst_name, fk_track_name),
FOREIGN KEY (fk_lst_name)
REFERENCES Playlists (lst_name)
ON DELETE CASCADE,
FOREIGN KEY (fk_track_name)
REFERENCES Tracks (track_name)
ON DELETE CASCADE
);
`
export async function first_run(){
db.exec([{ sql: 'PRAGMA foreign_keys = ON;', args: [] }], false, () =>
console.log('Foreign keys turned on')
);
db.transaction(tx => {
tx.executeSql(
`CREATE TABLE IF NOT EXISTS Playlists (
lst_name TEXT PRIMARY KEY,
date TEXT
);`,
null,
(tx1) => console.log('create table success2'),
(_, error) => console.log(error)
);
tx.executeSql(
`CREATE TABLE IF NOT EXISTS Tracks (
track_name TEXT PRIMARY KEY,
date TEXT
);`,
null,
(tx1) => console.log('create table success3'),
(_, error) => console.log(error)
);
tx.executeSql(
`CREATE TABLE IF NOT EXISTS Linking (
fk_lst_name TEXT,
fk_track_name TEXT,
PRIMARY KEY (fk_lst_name, fk_track_name),
FOREIGN KEY (fk_lst_name)
REFERENCES Playlists (lst_name)
ON DELETE CASCADE,
FOREIGN KEY (fk_track_name)
REFERENCES Tracks (track_name)
ON DELETE CASCADE
);`,
null,
(tx1) => console.log('create table success4'),
(_, error) => console.log(error)
);
});
console.log(Localization.locale);
const dir_info = await FileSystem.getInfoAsync(TRACK_DIR);
if (!dir_info.exists){
FileSystem.makeDirectoryAsync(TRACK_DIR);
}
}