@@ -37,7 +37,8 @@ function Graph (storage, key, opts) {
3737 if ( ! opts ) opts = { }
3838 this . db = hyperdb ( storage , key , opts )
3939 this . _prefixes = Object . assign ( { } , opts . prefixes || constants . DEFAULT_PREFIXES )
40- this . _prefixes . _ = opts . base || constants . DEFAULT_BASE
40+ this . _basename = opts . base || constants . DEFAULT_BASE
41+ this . _prefixes . _ = this . _basename
4142 this . _indexes = opts . index === 'tri'
4243 ? constants . HEXSTORE_INDEXES_REDUCED
4344 : constants . HEXSTORE_INDEXES
@@ -61,10 +62,11 @@ function Graph (storage, key, opts) {
6162inherits ( Graph , events . EventEmitter )
6263
6364Graph . prototype . _onNew = function ( cb ) {
65+ this . _version = pkg . version
6466 const metadata = [
6567 [ '@version' , pkg . version ] ,
6668 [ '@index' , Object . keys ( this . _indexes ) . length === 3 ? 'tri' : 'hex' ] ,
67- [ '@name' , this . _prefixes . _ ]
69+ [ '@name' , this . _basename ]
6870 ]
6971 Object . keys ( this . _prefixes ) . forEach ( ( key ) => {
7072 if ( key !== '_' ) {
@@ -95,8 +97,8 @@ Graph.prototype.addPrefix = function (prefix, uri, cb) {
9597}
9698
9799Graph . prototype . getStream = function ( triple , opts ) {
98- const stream = this . db . createReadStream ( this . _createQuery ( triple ) )
99- return stream . pipe ( new HyperdbReadTransform ( this . db , this . _prefixes , opts ) )
100+ const stream = this . db . createReadStream ( this . _createQuery ( triple , { encode : ( ! opts || opts . encode === undefined ) ? true : opts . encode } ) )
101+ return stream . pipe ( new HyperdbReadTransform ( this . db , this . _basename , opts ) )
100102}
101103
102104Graph . prototype . get = function ( triple , opts , callback ) {
@@ -153,8 +155,7 @@ Graph.prototype.searchStream = function (query, options) {
153155 } else if ( ! Array . isArray ( query ) ) {
154156 query = [ query ]
155157 }
156- const plannedQuery = planner ( query )
157-
158+ const plannedQuery = planner ( query , this . _prefixes )
158159 var streams = plannedQuery . map ( ( triple , i ) => {
159160 const limit = ( options && i === plannedQuery . length - 1 ) ? options . limit : undefined
160161 return new JoinStream ( {
@@ -217,7 +218,7 @@ Graph.prototype._createQuery = function (pattern, options) {
217218 var types = utils . typesFromPattern ( pattern )
218219 var preferedIndex = options && options . index
219220 var index = this . _findIndex ( types , preferedIndex )
220- const encodedTriple = utils . encodeTriple ( pattern , this . _prefixes )
221+ const encodedTriple = utils . encodeTriple ( pattern , options . encode ? this . _prefixes : { _ : this . _basename } )
221222 var key = utils . encodeKey ( index , encodedTriple )
222223 return key
223224}
0 commit comments