-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathph-address.js
More file actions
42 lines (34 loc) · 1.03 KB
/
ph-address.js
File metadata and controls
42 lines (34 loc) · 1.03 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
//// Core modules
const path = require('path')
//// External modules
const { Sequelize, Op } = require('sequelize');
const PhAddressFinder = require('./ph-address-finder');
//// Modules
const APP_DIR = path.resolve(__dirname).replace(/\\/g, '/')
class PhAddress {
#sequelize
#Address;
constructor() { }
/**
* Create instance that uses sqlite3 database
*
* @param {String} storage Optional path to database
* @returns {Promise<PhAddressFinder>}
*/
async useSqlite(storage = '') {
if (!storage) {
storage = path.join(APP_DIR, 'sqlite/ph-addresses.db')
}
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: storage,
logging: false,
});
await sequelize.authenticate()
const Address = require('./sqlite/models/address')('Address', sequelize)
this.#sequelize = sequelize
this.#Address = Address
return new PhAddressFinder(sequelize, Address)
}
}
module.exports = PhAddress