Ein ORM, das auf OpenAI basiert, das eine einfache menschliche Sprache in SQL -Abfragen übersetzt und sie in einer Datenbank ausführt.
Unterstützt derzeit Datenbank -Dialekte: MySQL, PostgreSQL und SQLite.
Unterstützte Sprachen: Englisch, Deutsch, Französisch, Spanisch, Polnisch, Italienisch, Niederländisch, Portugiesisch, Ukrainisch, Arabisch, Chinesisch, Japanisch, Koreanisch, Türkisch und vieles mehr.
ormgpt.query( " give me post with id 1, all comments for this post and user information about author " ) ;Erzeugte Anfrage:
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 ;Antwort:
[
{
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 Bereiten Sie eine Datenbankschema -Datei vor, z. schema.sql . Diese Datei wird verwendet, um Abfragen zu generieren.
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" ,
} ) ;In den letzten zwei Jahren fand ich, dass Ormen im JavaScript -Ökosystem neue "Tage seit dem letzten JavaScript -Framework" waren. Und da AI ein heißes Schlagwort ist, habe ich mich entschlossen, ein wenig zu experimentieren, um beide zu kombinieren und ein Orm zu erstellen, das Openai verwendet, um SQL -Abfragen zu generieren. Bitte verwenden Sie dies nicht in der Produktion.
MIT