An incomplete list of suggestion to unify deno database drivers (more suggestions are wellcome).
- mysql
- postgres
- redis
- sqlite
- mongo
Would be nice to have reps have the actual db name instead of name creation (mango -> mongo)
There are different instantiation systems at the moment. Some pass the config
during instantiation, others have a connect
function that creates the instance and await the connection.
import { Mango } from "https://deno.land/x/mango/mod.ts"
const client = new Mango({ /* ... configs */ })
const db = await client.connect()
import { connect } from "https://deno.land/x/redis/mod.ts"
const redis = await connect({ hostname: "127.0.0.1", port: 6379 })
let mod.ts export an connect
function that creates an instance internally. I think in most usecases method calling is done to the connection instance, not to the db instance, no?
import { connect } from "https://deno.land/x/mysql/mod.ts"
const mysql = await connect({ /* config */ })
let connection have an execute
method instead of query
or this.executor.exec
.
Since query calls call execute internally and look if result.rows
is defined, we easily can do that with
connection.execute(…).then(data => data.rows)
I think there is no need to have that as a separate method.
I am also pretty sure there is a nicer way mapping to array/object than having the methods queryObject
and queryArray
in a similar way.
let startTransaction
be a async method that returns an instance instead of callback function
import { connect } from "https://deno.land/x/mysql/mod.ts"
const connection = connect({ /* config */ })
const transaction = await connection.startTransaction()
await transaction.execute(…)
await transaction.execute(…)
const result = await transaction.commit() /* or */ await transaction.rollback()
let connection have the logger built in and have a logLevel
and quiet
property instead of a configLogger
function or something similar.
import { connect } from "https://deno.land/x/mysql/mod.ts"
const connection = connect({ /* config */ })
connection.logLevel = "debug"
connection.quiet = true
I am aware that not all these suggestions are appliable on every driver and that some drivers have different methods and functionality (like mongo db). But I think the effort to have a common structure between them would pay off.
What do you think?
Have a look at some of the discussion in jeremyBanks/database#3 😃