# Dataset from in-memory data source?

**URL:** <https://forum.servoy.com/t/dataset-from-in-memory-data-source/20040>\
**Category:** Classic Servoy\
**Created:** [July 19, 2019, 9:28am UTC](https://forum.servoy.com/t/dataset-from-in-memory-data-source/20040 "2019-07-19T09:28:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [July 19, 2019, 9:28am UTC](https://forum.servoy.com/t/dataset-from-in-memory-data-source/20040/1 "2019-07-19T09:28:48Z")

</div>

Hi all,

I have added some in-memory data sources which dramatically speed up and simplify the display of lists with running totals by using SQL-windowing functions.  
Now the users would like to export the data and I would like to create a dataset based on the in-memory data source… (which is not shared with other users, so I don’t have a database server).  
I’d like to do something like:

```auto
var ds = databaseManager.getDataSetByQuery("mem",query,args,maxrows);

```

This does not work on Servoy 2019.03.1.  
I suppose the fallback option is to isolate the query and args as a function and rerun from the original data source…

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [July 19, 2019, 11:34am UTC](https://forum.servoy.com/t/dataset-from-in-memory-data-source/20040/2 "2019-07-19T11:34:48Z")

</div>

Hi Christian,

you can retrieve a dataset like this:

```auto
function getInMemDataset() {
	var _fs = datasources.mem.<TABLENAME>.getFoundSet();
	var _aCol = databaseManager.getTable(_fs).getColumnNames();
	
	_fs.loadAllRecords();
	
	return databaseManager.convertToDataSet(_fs, _aCol);
}

```

Hope this helps

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 19, 2019, 12:34pm UTC](https://forum.servoy.com/t/dataset-from-in-memory-data-source/20040/3 "2019-07-19T12:34:51Z")

</div>

Just to add to Marc’s answer.

The column names in the databaseManager.convertToDataSet() function are in fact optional.  
You can leave it out if you want to get all columns. But it’s a nice option to be able to cherry-pick the columns you want in your dataset.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [July 19, 2019, 1:34pm UTC](https://forum.servoy.com/t/dataset-from-in-memory-data-source/20040/4 "2019-07-19T13:34:29Z")

</div>

> ROCLASI:  
> You can leave it out if you want to get all columns. But it’s a nice option to be able to cherry-pick the columns you want in your dataset.

Nope… checked that.  
Although leaving out column names is possible, you will only get the pk column returned.

Documentation also points that way:

> // converts a foundset pks to a dataset  
> var dataset = databaseManager.convertToDataSet(foundset);

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 19, 2019, 1:36pm UTC](https://forum.servoy.com/t/dataset-from-in-memory-data-source/20040/5 "2019-07-19T13:36:30Z")

</div>

I stand corrected.

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [July 22, 2019, 9:51am UTC](https://forum.servoy.com/t/dataset-from-in-memory-data-source/20040/6 "2019-07-22T09:51:20Z")

</div>

Thanks but it wasn’t what I was looking for – maybe I wasn’t clear.  
I was hoping to run a query on the in-memory datasource rather than convert the whole thing (or specific columns) into a dataset… ![:-)]( "Smile")

---

<div class="post-metadata">

**Author:** ![kwpsd](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kwpsd](https://forum.servoy.com/u/kwpsd)\
**Post date:** [July 22, 2019, 6:21pm UTC](https://forum.servoy.com/t/dataset-from-in-memory-data-source/20040/7 "2019-07-22T18:21:39Z")

</div>

Hi, Christian.

Something like this:

```auto
    var query = datasources.mem.<IN_MEMORY_TABLE_NAME>.createSelect()
    
    query.where.add( query.columns.<COLUMN_NAME>.eq( 1 ) )
    
    foundset.loadRecords( query )

```

I hope this helps!

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [July 24, 2019, 3:42pm UTC](https://forum.servoy.com/t/dataset-from-in-memory-data-source/20040/8 "2019-07-24T15:42:07Z")

</div>

Hi Kim,

thanks, I will have to try that. I tend to build queries by hand and not to use the query builder…

---

<div class="post-metadata">

**Author:** ![kwpsd](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kwpsd](https://forum.servoy.com/u/kwpsd)\
**Post date:** [July 24, 2019, 4:25pm UTC](https://forum.servoy.com/t/dataset-from-in-memory-data-source/20040/9 "2019-07-24T16:25:41Z")

</div>

We converted 95% of our raw SQL queries into Query Builder and find it easier to use than raw SQL, especially for complex SQL statements. Also, the QB statements are guaranteed to be cross-compatible with different back-ends. The 5% not converted is due to the lack of QB functionality (e.g. case/when statements), but that is coming. Try QB…you may like it!
