Un ORM basé sur OpenAI qui traduit un langage humain simple en requêtes SQL et les exécute sur une base de données.
Prend actuellement en charge les dialectes de base de données: MySQL, PostgreSQL et SQLite.
Langues soutenues: anglais, allemand, français, espagnol, polonais, italien, néerlandais, portugais, ukrainien, arabe, chinois, japonais, coréen, turc et bien d'autres.
ormgpt.query( " give me post with id 1, all comments for this post and user information about author " ) ;Requête générée:
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 ;Réponse:
[
{
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 Préparez un fichier de schéma de base de données, par exemple schema.sql . Ce fichier sera utilisé pour générer des requêtes.
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" ,
} ) ;Au cours des deux dernières années, j'ai trouvé que Orms était de nouveaux "jours depuis le dernier cadre JavaScript" dans l'écosystème JavaScript. Et comme l'IA est un mot à la mode chaud, j'ai décidé d'expérimenter un peu pour combiner les deux et créer un ORM qui utilise OpenAI pour générer des requêtes SQL. Veuillez ne pas l'utiliser en production.
Mit