## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
• Create your own community
##### Activity
Chrizzly
@Chris2011
I used createDatabase but this is not correct, I just tried connect, but I don't know where my sqlite db file needs to be placed in the folder structure and how I say -> use this db file
the nSQL().on('ready') never fired
And I thought syntax is this: use connect and add dummy tables to your tables array (If you use the Desktop browser for test) and this array will be skipped as if the real db file will be found, right?
Chrizzly
@Chris2011

I need to go through and do a bunch of udpates to NanoSQL 2 and answer the outstanding issues, just been really busy with other things. Covid hasn’t helped!

No problem, I hoped that the project is still alive. I didn't find another one. Last commit was in october.

@ClickSimply and also, hope that you are fine and thx for responding anyway :)
Scott Lott
@only-cliches
@Chris2011 That’s not right at all, nanoSQL uses a special format for the tables and data, there’s not really an easy way to map nanoSQL onto an existing SQLite database.
nanoSQL needs to manage the database from the beginning, when you choose SQLite you’re just choosing the format nanoSQL saves the database in.
For example, nanoSQL let’s you change the indexes and columns of a table as much as you’d like. This isn’t possible if you’re using SQLite columnds and indexes, so nanoSQL actually stores the rows as JSON data in a single SQLite column (that way the schema can change as often as you’d like) and indexes are stored as a complete secondary table in SQLite.
So in reality, nanoSQL “columns” and “indexes” cannot map onto SQLite “columns” and “indexes” to provide all the features nanoSQL does, so nanoSQL ends up using SQLite as a key-value store more or less.
Chrizzly
@Chris2011

Ok, so what is the correct way now? My scenario: I created a cordova app with Vue, the vue cordova plugin and vuetify. I test my App on the Desktop browser and when I'm finish with everything I test it on my phone. For this I use NanoSQL to have a TEMP database which looks similar to the SQLite DB file that I have for my phone. On Desktop, I want to see the TEMP Database and on my phone, I want to use the real SQLite DB. So as you said, I just need to use createDatabse for Desktop with dummy tables and for the real world App I can use nSQL().connect with empty tables or is this really not possible?

So for this, I need to have my queries doubled? One for Desktop to test my app and one for the Real world? @ClickSimply

Chrizzly
@Chris2011
I have just simple CRUD operations, nothing more.
Scott Lott
@only-cliches
There’s a few things going on here…. I’m not sure what you would ever use dummy tables for. The actual tables should be in the createDatabase call in the app regardless of development or production mode.
The plugin will automatically detect if you’re in a browser and use IndexedDB and use SQLite if you’re running on device.
The tables need to always be in the createDatabase call so that NanoSQL knows the shape of the data in the tables and what tables are on device. It’s not SQLite where the schema is included in the database and follows it everywhere. In NanoSQL the schema is provided by you in the createDatabase call.
Chrizzly
@Chris2011

Ok, I will test this. Thx. I only need the "dummy tables" for the browser to test. Because at the end it will be an app for Android and for this I have a dedicated sqlite file (my-app.db). And I just needed the tables for testing in the browser. It will never run there. But on my mobile phone it also showed me the dummy tables, not the correct ones from my db file. Neither for createDatabase nor connect. This is why I was wondering.

But as I said, I will test what you told me and would like to come back to you to clarify when I was wrong. Thx :)

LeftWild
@LeftWild
I'm having a problem deploying the app to android as the database is not being created, however in development mode it works on the emulator with no problems. I'm using cordova. I'm not asking for storage permissions, is it required?
Scott Lott
@only-cliches
Yes, you need storage permission. SQLite has to put the database somewhere. :)
LeftWild
@LeftWild
Yeah i thought so too, but apparently SQLite Storage does that himself. After banging my head into the wall a few times and rebuilding the .apk without changing anything it worked, so I'm not sure what was wrong ahaha
Thanks for the answer!
Den-Gda
@Den-Gda
Hi, is it possible to select just an array of values, not an array of objects? for example in my graph subquery i have parameter select:["filedata"] and i get an array of objetcs [{filedata:'data1'}, {filedata:'data2'},...], how can i get just ['data1', 'data2'....]
Scott Lott
@only-cliches
There’s no way to do thtat built into the database, since you’re selecting essentially the keys you want.
would be easy to do a .map(o => o.filedata) on the results to get this outcome.
ingwey
@ingwey
Hello, does the upsert function works with the where condition[ "field", "IN", array ]?
Scott Lott
@only-cliches
Yes, it works with any where conditions.
when you do an upsert with a WHERE, it tries to find rows to match your request and performs the upsert on those rows. If no rows are found, nothing is inserted.
ingwey
@ingwey

Thanks for your feedback! Got some strange problems with the condition ["field1", "=", "", "AND", "field2", "IN",array]. This where caused an upsert for every row, where field1 is empty and the rows of the array for field2, where also field1 where empty.

Also how are async tasks processed like, my background process will search for changed entries saved on the device, and will upload them to a server, if device is online and at the meantime I will do my changes on other entries? Are there any major problems, so that I shut hold or keep the data save process, while the Update to the server is running?

Scott Lott
@only-cliches
Firstly, your where condition isn’t formatted correctly. It should be [["field1", "=", “”], "AND", ["field2", "IN",array]].
as far as async, it depends on the adapter/mode you’re using.
The memory mode and local storage are sync, just about everything else is async. You’re asking about server syncing with the local database, this is a difficult problem that nanoSQL doesn’t try to solve. You’ll need to build additional abstractions to accomplish syncing, then take those issues into consideration.
Alexandre
@Almaju
Would it be possible to create a nanoSQL app that is callable by an external SQL service for example Tableau?
Scott Lott
@only-cliches
I’m not sure what you mean by that?
Suresh Uputhula
@Suresh918
@ClickSimply nSQL().rawDump([], false, (table, row) => {
}).then((data) => {
console.log(data);
});
the above code is printing array of 0's ( [0,0,0,0..] instead of actual data
can you help me on this please
rawDump is not working properly
Edney Silva
@ednsinf
guys, when I install npm show this error: error C2672: '_Sort_unchecked': nenhuma função sobrecarregada correspondente encontrada (compilando
arquivo de origem leveldb-rocksdb\db\external_sst_file_ingestion_job.cc) [D:\Meus Projetos\Comprebusca\comprebusca\comprebusca-back\node_modules\rocksdb\deps\leveldb\leveldb.vcxproj]
c:\program files (x86)\microsoft visual studio\2017\buildtools\vc\tools\msvc\14.16.27023\include\algorithm(4034): error C2780: 'void std::_Sort_unchecked(_RanIt,_RanIt,iterator_traits<_Iter>::difference_type,_Pr)'
Edney Silva
@ednsinf
is any exist a backup service for nodejs?
Ronan LE MEILLAT
@eltorio

Hi Everybody, I'm new to NanoSQL, I build a small database, now I have 2 tables tracks and fixes.
My problem is that I cannot understand how to add a value to a field in my fixes table.
ie in an SQL language I want to do
UPDATE (fixes)
SET int_value = int_value +8324
WHERE track_id = 17 ;

The only thing that I succeed is to change int_value to 8324 with an upsert query, but it is not what i want to do I want to add 8324 to the current value…

Edney Silva
@ednsinf

// Add multiple new rows
nSQL("users")
.query("upsert",[{name:"billy",age:50}, {name: "jeb", age: 30}])
.exec().then..

//Set all accounts with a balance less than zero to closed.
nSQL("accounts")
.query("upsert",{status:"closed"})
.where(["balance","<",0])
.exec().then...

// Assuming the primary key is id, set the data in row 5 to the provided data
nSQL("users")
.query("upsert",{id:5, name:"billy", age:50})
.exec().then..

// Nested upsert
nSQL("users.age").query("upsert", 50).where(["name", "=", "billy"]).exec()

Ronan LE MEILLAT
@eltorio
Thanks Edney, that's how I currently did but what I want to do is
age: age+4 for example, not age: 50
murphy85
@murphy85
@Chris2011 Would you please describe which types you added to tsconfig for resolving the problem with SQLResultSet? I'm stuck at the same issue. I executed
npm install --save @types/websql
to add the websql type definitions. Is this correct?
sumeetdnq
@sumeetdnq
Hi, would like to know why cordova adapter requires permission to external storage? It could use app/internal storage?
any way to specify path for storage?
sumeetdnq
@sumeetdnq
@ClickSimply anything on this?
Scott Lott
@only-cliches
Hey @sumeetdnq The Cordova adapter uses SQLite. The SQLite database has to live somewhere on disk, so it needs access to the storage of the device. I don't think it needs external storage, should just be asking for normal storage permissions (which might include external storage).
sumeetdnq
@sumeetdnq
Ok, Thanks! Trying to check cordova plugin repo for source code but not able to find it! Can you please share link to it if possible?
Chrizzly
@Chris2011
@murphy85 will have a look soon for you. I got rid of nano-sql due to not fit my needs, but will find it back in the history :)
Raphaël Fleury-le veso
@rfleuryleveso

Hello,
When using the nsql cli, I encounter this error:

nanoSQL v2.3.7 CLI
Running on 18:51:49
C:\Users\rfleu\Desktop\Projets\FluxyBot\bot\node_modules\@nano-sql\core\lib\cli.js:205
throw new Error(e);
^

Error: SyntaxError: Cannot use import statement outside a module

Command line is:
nsql --outDir www --files index.ts (Provided by doc)

Node version is 15.9.0, tsc version is 4.1.3, npm version is 7.5.3

index.ts contents:

import { nSQL } from '@nano-sql/core';
import { InanoSQLTableConfig } from '@nano-sql/core/lib/interfaces';

export const tables: InanoSQLTableConfig[] = [
{
name: 'users',
model: {
'id:uuid': { pk: true },
'age:float': {},
'name:string[]': {},
'meta:obj[]': {
model: {
'key:string': {},
'value:any': {},
},
},
'*:any': {},
},
},
];

nSQL()
.createDatabase({
id: 'fluxy',
mode: 'SNP',
tables,
});