DenoDB Enables Wider Database Support |
Written by Kay Ewbank | |||
Thursday, 08 July 2021 | |||
There's an updated version of DenoDB that improves support for databases outside its main list of supported formats by allowing connections with a URL string. DenoDB is an ORM that supports the use of MySQL, SQLite, MariaDB, PostgreSQL and MongoDB for the secure JavaScript and TypeScript runtime Deno. DenoDB can be used to create tables, query tables, write data and set up table relationships all from code using an API. DenoDB provides predefined types to ensure developers using it can make use of intellisense in their IDEs. Deno is a JavaScript and TypeScript runtime from the creator of Node.js. Deno uses V8 and is built in Rust. It is described as secure by default as it has no file, network, or environment access, unless explicitly enabled. Setting up your database with DenoDB is a four-step process, starting with creating a connection to a database for use, then creating models or views by specifying which tables and fields you're going to use. The model is then added to your database instance. You can create new tables in your database if necessary. Once you've worked through those stages, you can query your models. For a developer coming from the database side of the fence, you'll need to think in terms of building a SQL query from multiple methods rather than just putting together a SQL Select with all the elements at once. However, you can get to the result you need, it's just a different mindset. You create queries using a set of methods for use with await. For example return all the records for a model or table: await Flight.all(); await Flight.select('departure').all(); would return all the records in the flight table. Field returns the table name followed by a field name. Passing a second parameter works as the AS SQL keyword. There is a Select method, but this is only part of what you might expect. It indicates which fields should be returned or selected from the query: await Flight.select('id').all(); There are a number of SQL clauses, so you can use groupBy, Where, most versions of Join, orderBy, and update is also supported for updating one or multiple records. The mathematical operators such as sum, avg, min etc are all there, so you can compute domain values. What's new in the latest release is the ability to use databases that aren't supported out of the box. The developers give the example of Redshift, but the technique can be generalised. The technique used is that you put together a const containing the host name, user name, password, and database, then use the new import {Database} method. DenoDB is available now on GitHub. More InformationRelated ArticlesDeno 1.10 Adds Web Storage API Support Node.js Even Its Creator Thinks Its Flawed To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Comments
or email your comment to: comments@i-programmer.info |