forked from GerbenAaltink/alopex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (31 loc) · 876 Bytes
/
index.js
File metadata and controls
33 lines (31 loc) · 876 Bytes
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
const Database = require('sqlite-async')
const TableProxy = require('./proxy')
/**
* Create new connection to database.
*
* By accessing an attribute an existing table will be returned
* or a new one will be created.
*
* See table class about how to do CRUD operations
*
* @example
* // Memory database
* const dataSet = await connect()
* const pk = await dataSet.myNewTableName.insert({'myNewColumnName': 'data'})
*
* @example
* // File database
* const dataSet = await connect('mydb.sqlite')
* const pk = await dataSet.myNewTableName.insert({'myNewColumnName': 'data'})
*
* @param {string} [name=":memory:"]
* @returns {Object} new Alopex instance.
*/
function connect (name) {
const dbName = name || ':memory:'
return Database.open(dbName).then((db) => {
db.dbName = dbName
return new Proxy(db, TableProxy)
})
}
module.exports = connect