Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
6f0ab58
Big ol work in progress for now
jrf0110 Jun 7, 2016
8856356
mosql by default
jrf0110 Jun 7, 2016
5a2fc73
Fix main exports
jrf0110 Jun 7, 2016
d3d4c31
Rog
jrf0110 Jun 7, 2016
70b8d5d
remove old file
jrf0110 Jun 9, 2016
c4310f5
Wrong client reference when releasing
jrf0110 Jun 9, 2016
57f98d4
Results transforms have access to query
jrf0110 Jun 10, 2016
5b1cda7
WIP readme
jrf0110 Jun 10, 2016
e5b46e3
Use PGPool
jrf0110 Jun 12, 2016
6abe9c5
Stream support
jrf0110 Jun 13, 2016
fc4013a
Fix typo
jrf0110 Jun 14, 2016
4aced9e
Added insert method
jrf0110 Jun 14, 2016
84ae879
Add stream support
jrf0110 Jun 14, 2016
eb03b13
Add returning support, columsn test
jrf0110 Jun 14, 2016
a5b0db8
Do not patch `Database` prototype;
jrf0110 Jun 15, 2016
234e7dd
Make it so that `.register(instanceof Table)` adapts the table to fit…
jrf0110 Jun 15, 2016
1c1104e
Some upsert stuff
jrf0110 Jun 15, 2016
685cc8c
only throw missing pool error if you actually execute a query
jrf0110 Jun 15, 2016
219eafe
Add query debug
jrf0110 Jun 15, 2016
84107fe
Inherit options.debug
jrf0110 Jun 15, 2016
730c724
Individual query middleware should not affect all queries from table
jrf0110 Jun 16, 2016
f8addd8
Allow for findOne( where, options )
jrf0110 Jun 16, 2016
1e18a64
Add debug mode
jrf0110 Jun 16, 2016
48d4d29
Debugger to transaction
jrf0110 Jun 16, 2016
5facf80
Fix output ordering
jrf0110 Jun 16, 2016
f9a544e
Allow for incremental table graphs
jrf0110 Jun 16, 2016
51c1336
Forgot to pass debug option to transaction
jrf0110 Jun 16, 2016
911aee7
Always log query debug (even if theres an error
jrf0110 Jul 2, 2016
a1f9c48
rc1
jrf0110 Jul 2, 2016
25475cc
Debug output for streams
jrf0110 Jul 3, 2016
862f866
chalk.orange doesn't exist
jrf0110 Jul 3, 2016
245b9cd
don't assume user's pgPool is the same version as ours
jrf0110 Jul 3, 2016
aa6ed41
typo
jrf0110 Jul 3, 2016
7881825
fix embedded relationships
jrf0110 Aug 9, 2016
5eabf2a
If only inserting one obj, return one obj
jrf0110 Aug 13, 2016
47323c0
wheres should be optional
jrf0110 Aug 14, 2016
a2d3ee7
Add joins
jrf0110 Aug 20, 2016
7a63928
Fix nested mixins
jrf0110 Aug 20, 2016
00c6679
Fix insert returning
jrf0110 Aug 21, 2016
988fc51
Fix table results/query transforms inheritence
jrf0110 Sep 4, 2016
6a90899
Make before filters work as expected
jrf0110 Sep 4, 2016
9303e6d
Always log query debug (even if theres an error
jrf0110 Sep 11, 2016
7c533d2
Always log query debug (even if theres an error
jrf0110 Sep 11, 2016
ef93b1e
allow column arrays
jrf0110 Oct 23, 2016
1ddaff4
GroupBy should use array
jrf0110 Oct 23, 2016
e064fd3
GroupBy should use array
jrf0110 Oct 23, 2016
34cd6fd
Fix findOne limit
jrf0110 Nov 20, 2016
3c2705f
Better highlight value replacing
jrf0110 Nov 27, 2016
dca6766
Better highlight value replacing
jrf0110 Nov 27, 2016
92fd905
Dedupe values
jrf0110 Nov 27, 2016
626183c
Mosqlbump
jrf0110 Nov 27, 2016
e80111a
Fix adapted table clone debug status
jrf0110 Nov 27, 2016
1fe19dd
Fix seconds display
jrf0110 Nov 27, 2016
a0d433d
Fix some pool stuff
jrf0110 Nov 28, 2016
87538f0
Add the name getter/setter
jrf0110 Dec 30, 2016
1fdce3e
Bump mongo
jrf0110 Jan 1, 2017
568bcfc
Fix streams never releasing clients
jrf0110 Nov 17, 2019
2737077
Do not call release in tx error
jrf0110 Jan 12, 2020
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
1,077 changes: 146 additions & 931 deletions README.md

Large diffs are not rendered by default.

27 changes: 16 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
var dirac = module.exports = require('./lib/dirac');
var utils = require('./lib/utils');
var diracSchema = require('./lib/dirac-table');
const Database = require('./lib/database');
const relationships = require('./middleware/relationships');
const Query = require('./lib/query');
const Table = require('./lib/query');

// Database Access
dirac.db = require('./lib/db');
module.exports = options => {
if ( typeof options === 'string' ){
options = { connectionString: options };
}

// Middleware
dirac.tableRef = require('./middleware/table-ref');
dirac.castToJSON = require('./middleware/cast-to-json');
dirac.embeds = require('./middleware/embeds');
dirac.dir = require('./middleware/dir');
dirac.relationships = require('./middleware/relationships');
return Database
.create( options )
.use( relationships() );
};

module.exports.relationships = relationships;
module.exports.query = ( q, options )=> Query.create( q, options );
module.exports.table = options => Table.create( options );
191 changes: 191 additions & 0 deletions inspiration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
var db = require('dirac')({ connectionString })

db.users = db.table('users')
.stream({ concurrency: 10 })
.where({ id: { $gt: 100 } })
.map()

//

var db = require('dirac')({ connectionString: '...' })

db.users = db.dal({
name: 'users'
, schema: {...}
})

db.users
.find()
.where({ id: { $gt: 100 } })
.where('id.$or.$lt', 500)
.exec()
.then( users => ... )
.catch( error => ... )

// ...
( db )=>{
db.before
}

db.users.findOne(100)
.options({
many: [ { table: 'orders'
, many: [ ... ]
}
]
})

db.users.findOne(100)
.many({ table: '' })

//

db.tx().begin()
// Update book 123
.then( tx => {
return db.books.update(123)
.values({ likes: { $inc: 1 } })
.returning('*')
.exec( tx )
})
// Update the book author's total likes
.then( tx => {
// Transaction results are accumulated on `tx.results`
// We know the result is a single object since the operation
// was updating the table via the singular condition by primary key
return db.authors.update( tx.results.book.author_id )
.values({ total_likes: { $inc: 1 } })
.returning('*')
.exec( tx )
})
.then( tx => tx.commit() )
.catch( error => tx.abort() )
.then( results => {
res.json( results.book );
});

//

var query = users
.findOne(123)
// Find orders in parallel
.and( orders.find().where({ user_id: 123 }) )
// Results accumulate on an object
// Map the result to just the user object
.map( result => {
result.user.orders = result.orders;
return result.user;
})
// After that, insert something requiring the user data
.then( user => user_thing.insert({ foo: 'bar', user }) )

db.execute( query )
.then( user => res.json( user ) )
.catch( error => res.error( error ) )

//

var db = require('dirac')()
// Use .register to automatically add the table to
// the database instance (each register call creates
// a new instance unless options.immutable: false).
// As new tables are registered, the dependency graph
// is updated
.register(
db.table({
name: 'users'
, schema: {
id: { type: 'serial', primaryKey: true }
, name: { type: 'text' }
}
})
// If you want to map all results from this query factory to
// an application model, you could do something like this:
.after( users => {
if ( Array.isArray( users ) ){
return users.map( user => UserModel.create( user ) )
}

// Otherwise, they used a method that returned one result
return UserModel.create( users )
})
)
// Optionally, just pass in the table definition to register
.register({
name: 'books'
, schema: {
id: { type: 'serial', primaryKey: true }
, name: { type: 'text' }
}
})
.register({
name: 'user_books'
, schema: {
user_id: { type: 'int', references: { table: 'users', column: 'id' } }
, book_id: { type: 'int', references: { table: 'books', column: 'id' } }
}
})

// Remove user 123 returning the user object
// and the user's books
var query = db.users
.remove(123)
.returning('*')
.many(
db.query()
.table('user_books')
.alias('books')
.mixin('books')
);

// Note: user instanceof UserModel === true
query.exec().then( user => console.log( user.books[0].name ) )

// Notes on transactions
//
db.transaction()
.begin( tx => {

tx.query( )
.then( ()=> {



})
.then( ()=> tx.commit() )
})

// Transactions should behave more like Queries
// where calling .query(..) simply adds queries to the transaction
// building up a transaction plan
// and .execute() would execute that plan
var createUser = user => {
return db.transaction()
// Insert base user object
.query( tx => db.users.insert(user) )
// Insert user's groups with the new user_id assigned
.query( tx => {
let groups = user.groups.map( group => {
return Object.assign( { user_id: tx.user.id }, group )
})

return tx.query( db.user_groups.insert(groups) )
})
}

var createOrder = order => {
return db.transaction()
// Insert base order
.query( tx => db.orders.insert(order) )
// Also, update the order_statuses table
// This is a bit of a contrived example since you'd probably do this with triggers
.query( tx => db.order_statuses.insert({ order_id: tx.order.id, }))
}

// This way, you can compose transactions
createUser(user)
.query( tx => createOrder( Object.assign(order, { user_id: tx.user.id } ) ) )
.execute()
.then( results => {
console.log( results.user, results.order );
})
107 changes: 0 additions & 107 deletions lib/alter-table-sync-strategies.js

This file was deleted.

63 changes: 0 additions & 63 deletions lib/class.js

This file was deleted.

Loading