Socket
Socket
Sign inDemoInstall

final-orm

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

final-orm - npm Package Compare versions

Comparing version 1.0.0-alpha.3 to 1.0.0-alpha.4

5

index.test.js

@@ -122,3 +122,3 @@ import dotenv from 'dotenv'

const posts = await Post.find({
sort: 'post.createdAt asc',
sort: 'createdAt asc',
limit: 100

@@ -130,2 +130,3 @@ })

expect(isEqual(posts, sorted)).toBe(true)
expect(isEqual(posts, sorted.reverse())).not.toBe(true)
})

@@ -164,6 +165,4 @@

console.log('users', users)
expect(isEmpty(users)).toBe(true)
// expect(statuses.includes(true) !== true).toBe(true)
})

26

models/model.js

@@ -216,10 +216,22 @@ import arangojs, { aql } from 'arangojs'

let query = `
for ${item} in ${this.name} filter ${item}._removed != true
${where ? getWhere() : ''}
${(limit || skip) ? ` limit ${skip ? skip + ', ' : ''}${limit || 100}` : ''}
${(sort) ? ` sort ${sort}` : ''}
${(attributes || include) ? getAttributes() : `return ${item}`}
`
let query = `for ${item} in ${this.name} filter ${item}._removed != true`
if (where) {
query += getWhere()
}
if (limit || skip) {
query += ` limit ${skip ? skip + ', ' : ''}${limit || 100}`
}
if (sort) {
query += ` sort ${item}.${sort}`
}
if (attributes || include) {
query += getAttributes()
} else {
query += ` return ${item}`
}
const cursor = await db.query(query)

@@ -226,0 +238,0 @@ const documents = await cursor.all()

{
"name": "final-orm",
"version": "1.0.0-alpha.3",
"version": "1.0.0-alpha.4",
"repository": {

@@ -5,0 +5,0 @@ "type": "git",

@@ -1,3 +0,5 @@

ORMjs this is javascript OOP interface for ArangoDB
# Final ORM
Is a javascript OOP interface for ArangoDB
Based off of part of the ui-js code found here: https://github.com/uMaxmaxmaximus/ui-js/tree/master/server/core/orm

@@ -43,3 +45,3 @@

```javascript
var orm = require('ormjs')
var orm = require('final-orm')
var options = {

@@ -72,23 +74,23 @@ database: 'test', // db name

class User extends Model {
static schema = {
// basic types
name: String,
male: Boolean,
age: Number,
birth: Date,
tags: Set, // like array but items are unique
static schema = {
// basic types
name: String,
male: Boolean,
age: Number,
birth: Date,
tags: Set, // like array but items are unique
// structures
messages: [String], // array of types
prop1: {prop2: [{tags: [String]}] }, // sub schemas
// structures
messages: [String], // array of types
prop1: {prop2: [{tags: [String]}] }, // sub schemas
// relations with other (or self) db collections
bestFriend: User, // link to model
friends: [User], // link to array models
// relations with other (or self) db collections
bestFriend: User, // link to model
friends: [User], // link to array models
// field options
name: String,
name: {$type: String},
name: {$type: String, test: /^\w+$/},
status: {
// field options
name: String,
name: {$type: String},
name: {$type: String, test: /^\w+$/},
status: {
$type: String,

@@ -98,3 +100,3 @@ enum: ['sleep', 'eat'], // enum

}
}
}
}

@@ -120,6 +122,6 @@

static schema = {
name: String,
age: Number,
}
static schema = {
name: String,
age: Number,
}

@@ -134,26 +136,26 @@ }

// adding user to db
var user = await User.add({
name: 'Ашот',
age: 24,
})
// adding user to db
var user = await User.add({
name: 'Ашот',
age: 24,
})
user._id // 'User/434370324723'
user._removed // false
user.name // 'Ашот'
user.age // 24
user._id // 'User/434370324723'
user._removed // false
user.name // 'Ашот'
user.age // 24
// change field
user.name = 'Ololo'
console.log(user.name) // 'Ololo' field is changed
// change field
user.name = 'Ololo'
console.log(user.name) // 'Ololo' field is changed
// reset changes
await user.update() // load state from db
user.name // 'Ашот'
// reset changes
await user.update() // load state from db
user.name // 'Ашот'
// saving changes
user.name = 'Ololo' // change field
await user.save() // save changes to db
await user.update() // load state from db
user.name // 'Ololo' because we save
// saving changes
user.name = 'Ololo' // change field
await user.save() // save changes to db
await user.update() // load state from db
user.name // 'Ololo' because we save

@@ -232,5 +234,5 @@ // like via edge collection

static schema = {
size: Number
}
static schema = {
size: Number
}

@@ -242,6 +244,6 @@ }

static schema = {
name: String,
sector: Sector,
}
static schema = {
name: String,
sector: Sector,
}

@@ -257,21 +259,21 @@ }

var sector = await Sector.add({
size: 236
})
var sector = await Sector.add({
size: 236
})
var user = await User.add({
name: 'Ашот',
sector: sector
})
var user = await User.add({
name: 'Ашот',
sector: sector
})
(await user.sector).size // 236
(await user.sector).size // 236
var sector2 = await Sector.add({
size: 1004
})
user.sector = sector2
await user.save()
var sector2 = await Sector.add({
size: 1004
})
user.sector = sector2
await user.save()
(await user.sector).size // 1004 because this another sector ^__^
(await user.sector).size // 1004 because this another sector ^__^

@@ -293,23 +295,23 @@

constructor(r, g, b) {
this.r = r
this.g = g
this.b = b
}
constructor(r, g, b) {
this.r = r
this.g = g
this.b = b
}
// convert to db document
toJSON() {
return {
r: this.r,
g: this.g,
b: this.b
}
}
// convert to db document
toJSON() {
return {
r: this.r,
g: this.g,
b: this.b
}
}
// restore from db document
static fromJSON(json) {
return new Color(json.r, json.g, json.b)
}
// restore from db document
static fromJSON(json) {
return new Color(json.r, json.g, json.b)
}

@@ -321,6 +323,6 @@ }

static schema = {
name: String,
color: Color
}
static schema = {
name: String,
color: Color
}

@@ -335,8 +337,8 @@ }

var user = await User.add({
name: 'Ашот',
color: new Color(0, 255, 0)
})
var user = await User.add({
name: 'Ашот',
color: new Color(0, 255, 0)
})
user.color instanceof Color //true
user.color instanceof Color //true

@@ -352,5 +354,5 @@ }())

schema = {
age: Number,
age: {$type: Number},
age: {$type: Number, min:0, max:100}
age: Number,
age: {$type: Number},
age: {$type: Number, min:0, max:100}
}

@@ -363,5 +365,5 @@ ```

schema = {
name: String,
name: {$type: String},
name: {$type: String, min:3, max:20, test:/^\w+$/}
name: String,
name: {$type: String},
name: {$type: String, min:3, max:20, test:/^\w+$/}
}

@@ -374,5 +376,5 @@ ```

schema = {
tags: Set,
tags: {$type: Set},
tags: {$type: Set, set: ['animals', 'porn', 'movie']}
tags: Set,
tags: {$type: Set},
tags: {$type: Set, set: ['animals', 'porn', 'movie']}
}

@@ -379,0 +381,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc