Giter Site home page Giter Site logo

schmavery / drizzle-postgis Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 3.0 506 KB

A Drizzle extension/plugin to help work with PostGIS and GeoJSON

Home Page: https://schmavery.github.io/drizzle-postgis/

License: MIT License

TypeScript 100.00%
drizzle geojson postgis

drizzle-postgis's Introduction

๐ŸŒ drizzle-postgis

A Drizzle extension/plugin to help work with PostGIS and GeoJSON


Bug report ยท Feature request ยท Read Docs



๐Ÿšธ Disclaimer

I'm a GIS beginner, please let me know if you see anything problematic in the way this library is implemented. The library is also missing support for very many functions. PRs are very welcome, all I ask is that you add test coverage for any new functions :)

๐ŸŽ‰ Installation

pnpm add drizzle-postgis

Patching drizzle-kit (See Troubleshooting for more info) is no longer required in most cases (unless you need to generate migrations with a box2d type).

โ“Troubleshooting

If you're having trouble with Postgres complaining that the functions can't be found, try using config.setPostGISSchema("<schema>")

There's more information about how to use these functions here: https://postgis.net/docs/reference.html

NOTE for people using box2d

Unfortunately drizzle-kit has a bug that causes some custom types to be quoted. The only type in this library that is still affected (as of drizzle-kit 0.22.0) is box2d. In order to use this with migrations, you need to apply a patch (see below). This issue tracks this problem somewhat: drizzle-team/drizzle-kit-mirror#350

Step 1: Obtain the Patch File

The patch file is located in repository under the patches directory: patches/drizzle-kit@<version>.patch. (Replace with your installed version of drizzle-kit).

You can copy the patch file content directly from the repository to your local patches directory.

Step 2: Apply the Patch

If you're using pnpm, you can apply the patch by adding the following lines to your package.json file under the pnpm section:

  "pnpm": {
    "patchedDependencies": {
      "drizzle-kit@<version>": "patches/drizzle-kit@<version>.patch"
    }
  }

This configuration tells pnpm to apply the specified patch to the drizzle-kit@<version> dependency. Note that patches/drizzle-kit@<version>.patch is the path to the patch file

After updating your package.json, run pnpm install to install the patched dependency.

Alternative: Manual Patching (not recommended)

If you prefer not to modify your package.json, you can manually apply the patch using the patch command:

  1. Save the patch file content to a local file, e.g., drizzle-kit.patch.
  2. Navigate to the directory where drizzle-kit is installed (usually node_modules/drizzle-kit).
  3. Run the following command: patch -p1 < /path/to/drizzle-kit.patch

This will apply the patch to the drizzle-kit dependency.

๐Ÿ“š Auto generate docs

The project is configured to auto-generate the documentation using typedoc. The documentation is generated in the docs folder.

The documentation will get generated when the code is pushed to the main branch. You can also generate the documentation locally by running the command pnpm run build:docs.

๐Ÿซฑ๐Ÿปโ€๐Ÿซฒ๐Ÿผ Contributing

Please make sure to follow the conventional commit messages format while making changes. This helps in generating changelogs and versioning the package.

๐Ÿ™ Thanks to

drizzle-postgis's People

Contributors

akashrajpurohit avatar ehsan2003 avatar findingakash avatar nrdobie avatar renovate[bot] avatar schmavery avatar zegnat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

drizzle-postgis's Issues

Private package error

I want to try this package. But is it private package or deleted?

When i try to pnpm add drizzle-postgis, below error occurs.

โ€‰ERR_PNPM_FETCH_404โ€‰ GET https://registry.npmjs.org/drizzle-postgis: Not Found - 404

This error happened while installing a direct dependency of C:\code\orgs\hhyg\hilchin

drizzle-postgis is not in the npm registry, or you have no permission to fetch it.

An authorization header was used: Bearer npm_[hidden]

"TypeError: col.shouldDisableInsert is not a function" prevents inserts with [email protected] and [email protected]

First of all, thanks for your work with this great package!

I have encountered with an issue using the latest drizzle packages,
when trying to insert rows which contains fields with drizzle-postgis models.

My schema is:

const locationTable = createTable('location', {
  id: uuid('id')
    .default(sql`gen_random_uuid()`)
    .primaryKey(),
  coordinate: gis.point('coordinate', { srid: 4326 }).notNull()
})

and the code for the insert:

import { type db } from '@/server/db'
import { location } from '@/server/db/schema'

import { faker } from '@faker-js/faker'
import { Point } from 'drizzle-postgis'

const point = { type: "Point", coordinates: [faker.location.longitude(), faker.location.latitude()] } satisfies Point
const rows = [{
      id: faker.string.uuid(),
      coordinate: point
}]

await db.insert(location).values(rows)

Running the code above the following exception is thrown:

Stacktrace:

TypeError: col.shouldDisableInsert is not a function
    at <anonymous> (D:\Projects\dh\node_modules\src\pg-core\dialect.ts:459:94)
    at Array.filter (<anonymous>)
    at PgDialect.buildInsertQuery (D:\Projects\dh\node_modules\src\pg-core\dialect.ts:459:68)
    at QueryPromise.getSQL (D:\Projects\dh\node_modules\src\pg-core\query-builders\insert.ts:307:23)
    at <anonymous> (D:\Projects\dh\node_modules\src\pg-core\query-builders\insert.ts:322:35)
    at Object.startActiveSpan (D:\Projects\dh\node_modules\src\tracing.ts:27:11)
    at QueryPromise._prepare (D:\Projects\dh\node_modules\src\pg-core\query-builders\insert.ts:317:17)
    at <anonymous> (D:\Projects\dh\node_modules\src\pg-core\query-builders\insert.ts:332:16)
    at Object.startActiveSpan (D:\Projects\dh\node_modules\src\tracing.ts:27:11)
    at QueryPromise.execute (D:\Projects\dh\node_modules\src\pg-core\query-builders\insert.ts:331:17)

By checking drizzle's source code here, I think the column class has been extended with a new method shouldDisableInsert, which is not found on the custom columns generetad by this package.

Missing patch for [email protected] and [email protected], more instructions needed to setup.

Thanks a lot for creating this package.

I am trying to build an app on top of an existing PostGIS database,
i wanted to use the drizzle-kit inspect command to build the schema,
from what i understand i need to patch drizzle-kit,
but there's no patch for [email protected].

Furthermore I was looking for a simple setup example,
but couldn't find any, it would be very useful to add a simple
use case scenario in the readme.

Thanks again.
If any support is needed for the development, I am available for contributions.

migrate to newer drizzle kit

after the latest drizzle (0.22) patching it is no longer required
and the drizzle itself added support for basic geographic types ( altough I still prefer this approach since it gives me simple geojson )

and as far as I know the library gives us some errors ( altough I forgot to screenshot them )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.