ormGPT
1.0.0
ORM ที่ใช้ OpenAI ที่แปลภาษามนุษย์ธรรมดาเป็นแบบสอบถาม 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 เป็นวันใหม่ "วันนับตั้งแต่ Framework JavaScript ครั้งสุดท้าย" ในระบบนิเวศ JavaScript และเนื่องจาก AI เป็น buzzword ที่ร้อนแรงฉันจึงตัดสินใจทดลองใช้เล็กน้อยเพื่อรวมทั้งสองและสร้าง ORM ที่ใช้ OpenAI เพื่อสร้างแบบสอบถาม SQL โปรดอย่าใช้สิ่งนี้ในการผลิต
มิกซ์