App users can ask questions in multi-lingual natural language and AI agent will automatically generate and run SQL queries to fetch the data from DB source. Based on the obtained records, the LLM responds with deeper insights in a conversational manner.
- Next.js
- Vercel’s AI SDK
- Drizzle ORM
- SQLite Turso DB
- Clerk for application Authentication
- CI/CD and Deployed on Vercel
- Groq LLM Models
- Auto Scroll ref.
- Auto Resize input text area ref.
- Clerk Integration for Auth and SSO sign-in and sign-up.
- Loading Animate
- SQL Data Governance Security.
- Code-First ORM strategy for DB Migration.
- CI/CD Deployment to Vercel.
- Groq Cloud API Key
- Turso SQLite DB URL and Auth token.
- Clerk Public Key and Token.
- Create
.envfile in root (refer.env.examplefor keys creation) - Install project dependencies
pnpm install
-
[Optional] Write your own schema in
schema.tsor use the one with product and sales. -
[Optional] Seeding data via
seed.ts(change this file for any new tables) or use the given datasets. -
NOTE: The Agent uses aiPermittedTablesView for sensitive DB table masking (views and object can also be added). Please make use of this to hide any db objects from Agent Select queries.
-
- Add your db objects in the below view in
schema.tsaccordingly. This view is Mandatory on your Turso DB.
- Add your db objects in the below view in
export const aiPermittedTablesView = sqliteView(
'ai_permitted_tables_view',
{
type: text('type'),
name: text('name'),
tbl_name: text('tbl_name'),
sql: text('sql'),
},
).as(sql
`
SELECT type, name, tbl_name, sql
FROM sqlite_master
WHERE (type = 'table' OR type = 'view')
AND sql IS NOT NULL
AND tbl_name NOT LIKE '\\__%' ESCAPE '\\'
AND tbl_name NOT IN (
'sqlite_sequence',
'movies',
'actors'
)
AND name NOT IN (
'ai_permitted_tables_view'
)
`
);
- Generate DB tables
pnpm db:generate
- Migrate DB tables to Turso DB
pnpm db:migrate
- Seed the DB
npx bun run src/db/seed.ts
- Build local setup
pnpm build
- Finally, run the development server:
pnpm dev
Open http://localhost:3000 with your browser, to begin the Vinz Query-osity SQL AI Agent chat window for your AI powered SQL chat!
This is a Next.js project.