Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
dist
.env
45 changes: 43 additions & 2 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { isEqual, sortBy, isEmpty } from 'lodash'

dotenv.config()

const { NAME } = process.env
const { NAME, TEST_EXTERNAL_HOST } = process.env

const username = `test${randomBytes(8).toString('hex')}`

const db = ormjs.connect({
let db = ormjs.connect({
database: NAME || 'test'
})

Expand Down Expand Up @@ -208,3 +208,44 @@ test('complex query', async () => {

expect(posts.data[0].creator.name).toBe(username)
})

test('connect without localhost', async () => {
/*
The purpose of this test is to be sure other hosts work. I use ngrok like so

bash> ngrok http 127.0.0.1:8529

ngrok will output a WAN address like `123abc.ngrok.io` which you should make TEST_EXTERNAL_HOST in your env.

https://github.com/OKNoah/final-orm/issues/16
*/
db = ormjs.connect({
host: TEST_EXTERNAL_HOST,
protocol: 'https',
port: 443,
user: 'root',
password: '',
database: NAME || 'test'
})

class User2 extends db.Model {
static schema = {
name: { $type: String, index: true, unique: true },
profile: {
vegan: { $type: Boolean, optional: true }
}
}
}

const newUserName = username + '123'

await User2.add({ name: newUserName })

const user = await User2.findOne({
where: { name: newUserName }
})

expect(TEST_EXTERNAL_HOST).not.toBe(undefined)
expect(user).toHaveProperty('createdAt')
expect(moment(user.createdAt).isValid()).toBe(true)
})
3 changes: 2 additions & 1 deletion models/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default class Model {
const port = this.options.port || 8529
const username = this.options.username || 'root'
const password = this.options.password || ''
const url = this.options.url || `http://${username}:${password}@${host}:${port}`
const protocol = this.options.protocol || `${host === 'localhost' ? 'http' : 'https'}`
const url = this.options.url || `${protocol}://${username}:${password}@${host}:${port}`

const db = arangojs({
url
Expand Down
6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ create init class model.js
var orm = require('final-orm')
var options = {
database: 'test', // db name
// You can initialize the database using a url.
// You can initialize the database using just a url.
url: 'http://root:@localhost:8529',
// Or supply each of these values. You do not need both.
host: 'localhost',
port: '8529',
username: 'root',
password: ''
password: '',
// You can also supply a protocol. If localhost, it's `http` by default, otherwise `https`
protocol: 'tcp'
}

var { Model, Edge } = orm.connect(options)
Expand Down