1.3.0 • Published 1 month ago
@storecraft/database-turso v1.3.0
Storecraft Turso (libsql) Database support
Official libSql
/ Turso
driver for StoreCraft
on any platform.
Includes a vector store.
npm i @storecraft/database-turso
Local usage
import 'dotenv/config';
import http from "node:http";
import { App } from '@storecraft/core'
import { NodePlatform } from '@storecraft/core/platform/node';
import { NodeLocalStorage } from '@storecraft/core/storage/node'
import { LibSQL, LibSQLVectorStore } from '@storecraft/database-turso'
import { migrateToLatest } from '@storecraft/database-turso/migrate.js'
const app = new App(
{
auth_admins_emails: ['admin@sc.com'],
}
)
.withPlatform(new NodePlatform())
.withDatabase(
new LibSQL(
{
url: 'file:local.db',
}
)
)
.withStorage(new NodeLocalStorage('storage'))
.withVectorStore(
new LibSQLVectorStore(
{
embedder: new OpenAIEmbedder(),
url: 'file:local-vector.db'
}
)
).init();
await migrateToLatest(app.__show_me_everything.db, false);
await app.__show_me_everything.vector_store.createVectorIndex();
http.createServer(app.handler).listen(
8000,
() => {
app.print_banner('http://localhost:8000');
}
);
Storecraft will search the following env
variables
LIBSQL_URL=./data.db
# optional, if absent will use the same as LIBSQL_URL
LIBSQL_VECTOR_URL=./data-vector.db
So, you can instantiate with empty config
.withDatabase(
new Turso()
)
.withVectorStore(
new LibSQLVectorStore(
{
embedder: new OpenAIEmbedder(),
}
)
)
Cloud usage
connect to a cloud libsql
and Turso
platform
- First, login to your turso account.
- Create a database.
- Create an API Key.
usage
import 'dotenv/config';
import http from "node:http";
import { App } from '@storecraft/core'
import { NodePlatform } from '@storecraft/core/platform/node';
import { NodeLocalStorage } from '@storecraft/core/storage/node'
import { Turso, LibSQLVectorStore } from '@storecraft/database-turso'
import { migrateToLatest } from '@storecraft/database-turso/migrate.js'
const app = new App(
{
auth_admins_emails: ['admin@sc.com'],
}
)
.withPlatform(new NodePlatform())
.withDatabase(
new Turso(
{
prefers_batch_over_transactions: true,
// all of these configurations can be inferred by env variables at init
url: process.env.LIBSQL_URL,
authToken: process.env.LIBSQL_API_TOKEN,
}
)
)
.withStorage(new NodeLocalStorage('storage'))
.withVectorStore(
new LibSQLVectorStore(
{
embedder: new OpenAIEmbedder(),
url: process.env.LIBSQL_URL,
authToken: process.env.LIBSQL_API_TOKEN,
}
)
).init();
await migrateToLatest(app.__show_me_everything.db, false);
await app.__show_me_everything.vector_store.createVectorIndex();
http.createServer(app.handler).listen(
8000,
() => {
app.print_banner('http://localhost:8000');
}
);
Storecraft will search the following env
variables
LIBSQL_URL=libsql://<your_database_name>.something.com
LIBSQL_AUTH_TOKEN=your_api_key
So, you can instantiate with empty config
.withDatabase(
new Turso()
)
.withVectorStore(
new LibSQLVectorStore(
{
embedder: new OpenAIEmbedder(),
}
)
)
Author: Tomer Shalev <tomer.shalev@gmail.com>
1.0.19
3 months ago
1.0.18
3 months ago
1.0.17
3 months ago
1.0.16
3 months ago
1.2.5
2 months ago
1.3.0
1 month ago
1.0.22
2 months ago
1.0.21
2 months ago
1.0.20
3 months ago
1.0.23
2 months ago
1.0.15
3 months ago
1.0.14
3 months ago
1.0.13
4 months ago
1.0.12
4 months ago
1.0.11
4 months ago
1.0.10
4 months ago
1.0.9
4 months ago
1.0.8
5 months ago
1.0.7
5 months ago
1.0.6
6 months ago
1.0.5
8 months ago
1.0.2
9 months ago
1.0.4
9 months ago
1.0.3
9 months ago
1.0.1
9 months ago
1.0.0
11 months ago