1.0.11 • Published 3 months ago

@storecraft/database-turso v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Storecraft Turso (libsql) Database support

Official libSql / Turso driver for StoreCraft on any platforms. Includes a vector store.

npm i @storecraft/database-turso

Setup

You can run a local database, or,

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'],
    auth_secret_access_token: 'auth_secret_access_token',
    auth_secret_refresh_token: 'auth_secret_refresh_token'
  }
)
.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,
      // or local
      url: 'file:local.db',
    }
  )
)
.withStorage(new NodeLocalStorage('storage'))
.withVectorStore(
  new LibSQLVectorStore(
    {
      embedder: new OpenAIEmbedder()
    }
  )
)

await app.init();
await migrateToLatest(app.db, false);
 
const server = http.createServer(app.handler).listen(
  8000,
  () => {
    console.log(`Server is running on http://localhost:8000`);
  }
); 
Author: Tomer Shalev <tomer.shalev@gmail.com>
1.0.11

3 months ago

1.0.10

3 months ago

1.0.9

4 months ago

1.0.8

4 months ago

1.0.7

4 months ago

1.0.6

6 months ago

1.0.5

7 months ago

1.0.2

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.1

8 months ago

1.0.0

10 months ago