npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sequelize-with-spatialite

v0.1.0

Published

Use Spatialite extension of SQLite with Sequelize.

Downloads

8

Readme

Sequelize with Spatialite

A copy of Sequelize ORM with support for Spatialite extension in SQLite.

The original Sequelize ORM does not support Spatialite extension in SQLite. This package adds support for Spatialite extension in SQLite with Sequelize ORM.

Installation

npm install sequelize-with-spatialite

For any documentation on Sequelize, refer to the original Sequelize documentation remember to read v6 docs, this package is based on that. The code of this repo is based on the commit 505467b.

You can read Spatialite documentation here.

I recommend first reading my blog post on this Integrating Spatialite with Sequelize.

Usage

To use Spatialite in any SQLite database, you first need to initialize spatialite in the database. Run this query to initialize spatialite in the database. This query is only needed once for a database.

import { DataTypes, Sequelize } from "sequelize-with-spatialite";

const sequelize = new Sequelize({
    dialect: "sqlite",
    storage: "./db.sqlite", // path to your database file
    logging: false,
});

await sequelize.query("SELECT InitSpatialMetaData();");

That's it, Now you can use Sequelize for Post GIS data in SQLite with all the same syntax and notations as postgres.

const User = sequelize.define('User', {
    id: {
        type: Sequelize.UUID,
        primaryKey: true,
        defaultValue: Sequelize.UUIDV4 
    },
    name: {
        type: DataTypes.STRING,
        allowNull: false
    },
    location: {
        type: DataTypes.GEOMETRY('POINT'),
        allowNull: true
    },
    area: {
        type: DataTypes.GEOMETRY('POLYGON'),
        allowNull: true
    }
});

Insert data or Run migartions normally as you would do with Sequelize.

import circleToPolygon from 'circle-to-polygon';

const coordinates = [73.78291978700082, 20.06382394128455]; // longitude, latitude
const point = {type: "Point", coordinates: coordinates};
const radius = 10000; // in meters
const polygon = circleToPolygon(coordinates, radius, 32); // 32 is the number of edges

await User.create({
    name: "John Doe",
    location: point,
    area: polygon
});

Note: This package will not be actively maintained. I will ocassionally do bug fixes and updates, but I will not be adding new features or updating to new versions of Sequelize. If you want to use the latest features of Sequelize, you can use the original Sequelize package and use the spatialite package to use Spatialite extension in SQLite (which is messy, because you have to always use raw queries, hence I created this package.)

If you find any issues, feel free to open an issue or a pull request.