You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sqlite/README.md

62 lines
1.3 KiB

3 months ago
# Nano Sqlite
3 months ago
3 months ago
Functions and Classes for handle Sqlite in [Bun](https://bun.sh/).
3 months ago
## API
### getOrCreateSqlite(options = {})
3 months ago
As options the default Parameters from [Bun](https://bun.sh/docs/api/sqlite) are available.
The uri of the Sqlite can be set in the .env-file,
```
NANO_SQLITE_PATH="./../storage/db.sqlite"
```
3 months ago
or by Parameter in options,
```
3 months ago
const db = getOrCreateSqlite({ uri: './../storage/db.sqlite' })
const db = getOrCreateSqlite({ uri: ':memory:' })
```
3 months ago
Per Default WAL mode is enabled. To disable add Parameter "wal" and set to false,
```
3 months ago
const db = getOrCreateSqlite({ uri: './../storage/db.sqlite', wal: false })
```
### runMigrationSqlite(filePath: string, db: object)
3 months ago
This functions Reads SQL-Files from a Directory and execute them in the Sqlite.
### Store
3 months ago
Store is a Abstract Class to extend a Class for an Single Table. Set the name
of the table in super(). There is no handling of columns or validating if the
exists.
```
class <store-name>Store extends Store {
constructor(db) {
super(db, '<table-name>')
}
}
```
#### findOneById(id: integer)
3 months ago
Getting single row by id.
#### create(data: object)
Create a new row in a Table.
#### update(id: integer, data: object)
3 months ago
Update single row by id.
#### remove(id: integer)
3 months ago
Remove single row by id.