ormGPT
1.0.0
基於OpenAI的ORM,將普通的人類語言轉換為SQL查詢並在數據庫上執行它們。
當前支持數據庫方言:MySQL,PostgreSQL和SQLITE。
支持語言:英語,德語,法語,西班牙,波蘭語,意大利語,荷蘭語,葡萄牙語,烏克蘭,阿拉伯語,中文,日語,韓語,土耳其語等。
ormgpt.query( " give me post with id 1, all comments for this post and user information about author " ) ;生成查詢:
SELECT
p . id AS post_id,
p . title ,
p . body ,
c . id AS comment_id,
c . body AS comment_body,
u . username AS author_username,
u . email AS author_email
FROM
posts p
JOIN comments c ON p . id = c . post_id
JOIN users u ON u . id = p . user_id
WHERE
p . id = 1 ;回覆:
[
{
post_id : 1 ,
title : 'Hello world!' ,
body : 'This is my first post!' ,
comment_id : 1 ,
comment_body : 'Hello world!' ,
author_username : 'test' ,
author_email : '[email protected]'
}
] 
npm install ormgpt
# or
yarn add ormgpt
# or
pnpm add ormgpt準備數據庫架構文件,例如schema.sql 。此文件將用於生成查詢。
const client = await createConnection ( {
host : 'localhost' ,
port : 3306 ,
database : 'ormgpt' ,
user : 'root' ,
password : 'mysecretpassword' ,
} ) ;
const mysqlAdapter = new MysqlAdapter ( {
client
} ) ;
const ormgpt = new ormGPT ( {
apiKey : "OPENAI_API_KEY" ,
schemaFilePath : "./example/schema.sql" ,
dialect : "postgres" ,
dbEngineAdapter : mysqlAdapter ,
} ) ;
await ormgpt . query (
"add new user with username 'test' and email '[email protected]'" ,
) ;
const users = await ormgpt . query ( "get all users" ) ;
console . log ( users ) ;mysql
const client = await createConnection ( {
host : 'localhost' ,
port : 3306 ,
database : 'ormgpt' ,
user : 'root' ,
password : 'mysecretpassword' ,
} ) ;
const mysqlAdapter = new MysqlAdapter ( {
client
} ) ;Postgres
const client = new Client ( {
host : 'localhost' ,
port : 5432 ,
database : 'ormgpt' ,
user : 'mysecretuser' ,
password : 'mysecretpassword' ,
} ) ;
client . connect ( ) ;
const postgresAdapter = new PostgresAdapter ( {
client
} ) ;sqlite
const sqliteAdapter = new SqliteAdapter ( {
dbFilePath : "./example/db.sqlite" ,
} ) ;在過去的兩年中,我發現Orms是JavaScript生態系統中最近的JavaScript框架以來的新日子。而且,由於AI是一個熱門流行語,因此我決定進行一些嘗試以將兩者結合起來,並創建一個使用OpenAI生成SQL查詢的ORM。請不要在生產中使用它。
麻省理工學院