ORM berdasarkan OpenAi yang menerjemahkan bahasa manusia biasa ke dalam kueri SQL dan mengeksekusinya pada database.
Saat ini mendukung dialek basis data: MySQL, PostgreSQL, dan SQLite.
Bahasa yang didukung: Inggris, Jerman, Prancis, Spanyol, Polandia, Italia, Belanda, Portugis, Ukraina, Arab, Cina, Jepang, Korea, Turki, dan banyak lagi.
ormgpt.query( " give me post with id 1, all comments for this post and user information about author " ) ;Kueri yang dihasilkan:
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 ;Tanggapan:
[
{
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 Siapkan file skema basis data, misalnya schema.sql . File ini akan digunakan untuk menghasilkan kueri.
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" ,
} ) ;Dalam dua tahun terakhir, saya menemukan ORM sebagai "hari -hari baru sejak kerangka kerja JavaScript terakhir" di ekosistem JavaScript. Dan karena AI adalah kata kunci panas saya memutuskan untuk bereksperimen sedikit untuk menggabungkan keduanya dan membuat ORM yang menggunakan OpenAi untuk menghasilkan kueri SQL. Tolong jangan gunakan ini dalam produksi.
Mit