refactor (backend-rs): expose SeaORM entities to Node API
Co-authored-by: sup39 <dev@sup39.dev>
This commit is contained in:
parent
c52973234c
commit
aa11eeb1c8
3 changed files with 15 additions and 2 deletions
3
packages/backend-rs/Cargo.lock
generated
3
packages/backend-rs/Cargo.lock
generated
|
@ -1266,10 +1266,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "c4ca998356d8ff9fba7a070dae4508a2298439c98c9f3bc9c07669538b999e8f"
|
||||
dependencies = [
|
||||
"bitflags 2.5.0",
|
||||
"chrono",
|
||||
"ctor",
|
||||
"napi-derive",
|
||||
"napi-sys",
|
||||
"once_cell",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ thiserror = "1.0.58"
|
|||
tokio = { version = "1.36.0", features = ["full"] }
|
||||
|
||||
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
|
||||
napi = { version = "2.16.1", default-features = false, features = ["napi9", "tokio_rt"], optional = true }
|
||||
napi = { version = "2.16.1", default-features = false, features = ["napi9", "tokio_rt", "chrono_date", "serde-json"], optional = true }
|
||||
napi-derive = { version = "2.16.1", optional = true }
|
||||
basen = "0.1.0"
|
||||
|
||||
|
|
|
@ -2,7 +2,17 @@
|
|||
regenerate-entities:
|
||||
sea-orm-cli generate entity \
|
||||
--output-dir='src/model/entity' \
|
||||
--database-url='postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@localhost:25432/$(POSTGRES_DB)'
|
||||
--database-url='postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@localhost:25432/$(POSTGRES_DB)' \
|
||||
--date-time-crate='chrono' \
|
||||
--model-extra-attributes='NAPI_EXTRA_ATTR_PLACEHOLDER' && \
|
||||
for file in src/model/entity/*; do \
|
||||
base=$$(basename -- "$${file}"); \
|
||||
jsname=$$(printf '%s\n' "$${base%.*}" | perl -pe 's/(^|_)./uc($$&)/ge;s/_//g'); \
|
||||
attribute=$$(printf 'cfg_attr(feature = "napi", napi_derive::napi(object, js_name = "%s", use_nullable = true))' "$${jsname}"); \
|
||||
sed -i "s/NAPI_EXTRA_ATTR_PLACEHOLDER/$${attribute}/" "$${file}"; \
|
||||
done
|
||||
sed -i 's/#\[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)\]/#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]\n#[cfg_attr(not(feature = "napi"), derive(Clone))]\n#[cfg_attr(feature = "napi", napi_derive::napi)]/' \
|
||||
src/model/entity/sea_orm_active_enums.rs
|
||||
|
||||
index.js:
|
||||
NODE_OPTIONS='--max_old_space_size=3072' pnpm run build:debug
|
||||
|
|
Loading…
Reference in a new issue